Merge remote-tracking branch 'origin/errcode' into errcode

This commit is contained in:
skiffer-git
2023-01-31 20:33:48 +08:00
11 changed files with 491 additions and 181 deletions
+49
View File
@@ -0,0 +1,49 @@
package controller
import (
"Open_IM/pkg/common/db/relation"
pbMsg "Open_IM/pkg/proto/msg"
"gorm.io/gorm"
)
type ChatLogInterface interface {
CreateChatLog(msg pbMsg.MsgDataToMQ) error
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
}
func NewChatLogController(db *gorm.DB) ChatLogInterface {
return &ChatLogController{database: NewChatLogDataBase(db)}
}
type ChatLogController struct {
database ChatLogDataBaseInterface
}
func (c *ChatLogController) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
return c.database.CreateChatLog(msg)
}
func (c *ChatLogController) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
return c.database.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
}
type ChatLogDataBaseInterface interface {
CreateChatLog(msg pbMsg.MsgDataToMQ) error
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
}
type ChatLogDataBase struct {
chatLogDB *relation.ChatLog
}
func NewChatLogDataBase(db *gorm.DB) ChatLogDataBaseInterface {
return &ChatLogDataBase{chatLogDB: relation.NewChatLog(db)}
}
func (c *ChatLogDataBase) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
return c.chatLogDB.Create(msg)
}
func (c *ChatLogDataBase) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
return c.chatLogDB.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
}
+7 -6
View File
@@ -85,8 +85,8 @@ func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID strin
panic("implement me")
}
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoDB)}
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface {
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoClient)}
return groupController
}
@@ -133,23 +133,24 @@ type GroupDataBase struct {
mongoDB *unrelation.SuperGroupMgoDB
}
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupDataBaseInterface {
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupDataBaseInterface {
groupDB := relation.NewGroupDB(db)
groupMemberDB := relation.NewGroupMemberDB(db)
groupRequestDB := relation.NewGroupRequest(db)
newDB := db
superGroupMgoDB := unrelation.NewSuperGroupMgoDB(mgoClient)
database := &GroupDataBase{
groupDB: groupDB,
groupMemberDB: groupMemberDB,
groupRequestDB: groupRequestDB,
db: newDB,
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, rockscache.Options{
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, superGroupMgoDB, rockscache.Options{
RandomExpireAdjustment: 0.2,
DisableCacheRead: false,
DisableCacheDelete: false,
StrongConsistency: true,
}),
mongoDB: unrelation.NewSuperGroupMgoDB(mgoDB),
mongoDB: superGroupMgoDB,
}
return database
}
@@ -223,7 +224,7 @@ func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, in
return err
}
if err = g.cache.DelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
_ = sess.AbortTransaction(ctx)
return err
}