mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-09 12:39:02 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
Conflicts: pkg/common/db/controller/group.go pkg/common/db/relation/group_model_k.go
This commit is contained in:
commit
5e4e960524
@ -6,6 +6,7 @@ import (
|
|||||||
"Open_IM/pkg/common/db/unrelation"
|
"Open_IM/pkg/common/db/unrelation"
|
||||||
"context"
|
"context"
|
||||||
"github.com/dtm-labs/rockscache"
|
"github.com/dtm-labs/rockscache"
|
||||||
|
_ "github.com/dtm-labs/rockscache"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -32,23 +33,23 @@ func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
func (g *GroupController) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
||||||
return g.database.Find(ctx, groupIDs)
|
return g.database.FindGroupsByID(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation.Group) error {
|
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation.Group) error {
|
||||||
return g.database.Create(ctx, groups)
|
return g.database.CreateGroup(ctx, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
func (g *GroupController) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||||
return g.database.Delete(ctx, groupIDs)
|
return g.database.DeleteGroupByIDs(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error) {
|
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error) {
|
||||||
return g.database.Take(ctx, groupID)
|
return g.database.TakeGroupByID(ctx, groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
func (g *GroupController) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||||
return g.database.GetSuperGroup(ctx, groupID)
|
return g.database.GetSuperGroupByID(ctx, groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error {
|
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error {
|
||||||
@ -56,11 +57,11 @@ func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DataBase interface {
|
type DataBase interface {
|
||||||
Find(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
|
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
|
||||||
Create(ctx context.Context, groups []*relation.Group) error
|
CreateGroup(ctx context.Context, groups []*relation.Group) error
|
||||||
Delete(ctx context.Context, groupIDs []string) error
|
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||||
Take(ctx context.Context, groupID string) (group *relation.Group, err error)
|
TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error)
|
||||||
GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error
|
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,15 +93,15 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Datab
|
|||||||
return database
|
return database
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) Find(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
||||||
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) Create(ctx context.Context, groups []*relation.Group) error {
|
func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation.Group) error {
|
||||||
return g.groupDB.Create(ctx, groups)
|
return g.groupDB.Create(ctx, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) Delete(ctx context.Context, groupIDs []string) error {
|
func (g *GroupDataBase) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||||
return g.groupDB.DB.Transaction(func(tx *gorm.DB) error {
|
return g.groupDB.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
if err := g.groupDB.Delete(ctx, groupIDs, tx); err != nil {
|
if err := g.groupDB.Delete(ctx, groupIDs, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -112,7 +113,7 @@ func (g *GroupDataBase) Delete(ctx context.Context, groupIDs []string) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) Take(ctx context.Context, groupID string) (group *relation.Group, err error) {
|
func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error) {
|
||||||
return g.cache.GetGroupInfo(ctx, groupID)
|
return g.cache.GetGroupInfo(ctx, groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +137,6 @@ func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, in
|
|||||||
return g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList, memberNumCount, g.cache.DelJoinedSuperGroupIDs)
|
return g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList, memberNumCount, g.cache.DelJoinedSuperGroupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
func (g *GroupDataBase) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||||
return g.mongoDB.GetSuperGroup(ctx, groupID)
|
return g.mongoDB.GetSuperGroup(ctx, groupID)
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,16 @@ type Group struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupDB(db *gorm.DB) *Group {
|
func NewGroupDB(db *gorm.DB) *Group {
|
||||||
return &Group{DB: db}
|
var group Group
|
||||||
|
group.DB = db
|
||||||
|
return &group
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) Create(ctx context.Context, groups []*Group) (err error) {
|
func (g *Group) Create(ctx context.Context, groups []*Group, tx ...*gorm.DB) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||||
}()
|
}()
|
||||||
err = utils.Wrap(g.DB.Create(&groups).Error, "")
|
err = utils.Wrap(getDBConn(g.DB, tx).Create(&groups).Error, "")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,39 +45,40 @@ func (g *Group) Delete(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (
|
|||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(getDBConn(g.DB, tx...).Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
|
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) {
|
func (g *Group) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(g.DB.Where("group_id = ?", groupID).Updates(args).Error, "")
|
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(g).Updates(args).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) Update(ctx context.Context, groups []*Group, tx ...*gorm.DB) (err error) {
|
func (g *Group) Update(ctx context.Context, groups []*Group, tx ...*gorm.DB) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(getDBConn(g.DB, tx...).Updates(&groups).Error, "")
|
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) Find(ctx context.Context, groupIDs []string) (groups []*Group, err error) {
|
func (g *Group) Find(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (groups []*Group, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
|
||||||
}()
|
}()
|
||||||
err = utils.Wrap(g.DB.Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
err = utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
||||||
return groups, err
|
return groups, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) Take(ctx context.Context, groupID string) (group *Group, err error) {
|
func (g *Group) Take(ctx context.Context, groupID string, tx ...*gorm.DB) (group *Group, err error) {
|
||||||
group = &Group{}
|
group = &Group{}
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||||
}()
|
}()
|
||||||
err = utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "")
|
err = utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Take(group).Error, "")
|
||||||
return group, err
|
return group, err
|
||||||
}
|
}
|
||||||
func (g *Group) DeleteTx(ctx context.Context, groupIDs []string) error {
|
|
||||||
return nil
|
//func (g *Group) DeleteTx(ctx context.Context, groupIDs []string) error {
|
||||||
}
|
// return nil
|
||||||
|
//}
|
||||||
|
@ -87,7 +87,7 @@ func (w Writer) Printf(format string, args ...interface{}) {
|
|||||||
fmt.Printf(format, args...)
|
fmt.Printf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDBConn(db *gorm.DB, tx ...*gorm.DB) *gorm.DB {
|
func getDBConn(db *gorm.DB, tx []*gorm.DB) *gorm.DB {
|
||||||
if len(tx) > 0 {
|
if len(tx) > 0 {
|
||||||
return tx[0]
|
return tx[0]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user