mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-30 06:22:44 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
Conflicts: pkg/common/db/model/group.go
This commit is contained in:
commit
8d029a7ab3
@ -5,7 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/db/mongoDB"
|
||||
"Open_IM/pkg/common/db/mysql"
|
||||
"context"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
_ "github.com/dtm-labs/rockscache"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"gorm.io/gorm"
|
||||
@ -19,32 +19,52 @@ type GroupInterface interface {
|
||||
Take(ctx context.Context, groupID string) (group *mysql.Group, err error)
|
||||
}
|
||||
|
||||
type GroupModel struct {
|
||||
db mysql.GroupModelInterface
|
||||
type GroupController struct {
|
||||
db DataBase
|
||||
cache *cache.GroupCache
|
||||
mongo *mongoDB.Client
|
||||
}
|
||||
|
||||
func NewGroupModel(db mysql.GroupModelInterface, rdb redis.UniversalClient, mdb *mongo.Client) *GroupModel {
|
||||
var groupModel GroupModel
|
||||
groupModel.db = db
|
||||
groupModel.cache = cache.NewGroupCache(rdb, db, rockscache.Options{
|
||||
DisableCacheRead: false,
|
||||
StrongConsistency: true,
|
||||
})
|
||||
groupModel.mongo = mongoDB.NewMongoClient(mdb)
|
||||
return &groupModel
|
||||
type DataBase interface {
|
||||
Find(ctx context.Context, groupIDs []string) (groups []*mysql.Group, err error)
|
||||
Create(ctx context.Context, groups []*mysql.Group) error
|
||||
Delete(ctx context.Context, groupIDs []string) error
|
||||
Take(ctx context.Context, groupID string) (group *mysql.Group, err error)
|
||||
DeleteTx(ctx context.Context, groupIDs []string) error
|
||||
}
|
||||
type MySqlDatabase struct {
|
||||
mysql.GroupModelInterface
|
||||
}
|
||||
|
||||
func (g *GroupModel) Find(ctx context.Context, groupIDs []string) (groups []*mysql.Group, err error) {
|
||||
func (m *MySqlDatabase) Delete(ctx context.Context, groupIDs []string) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewMySqlDatabase(db mysql.GroupModelInterface) DataBase {
|
||||
return &MySqlDatabase{db}
|
||||
}
|
||||
func (m *MySqlDatabase) DeleteTx(ctx context.Context, groupIDs []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewGroupController(groupModel mysql.GroupModelInterface, rdb redis.UniversalClient, mdb *mongo.Client) *GroupController {
|
||||
return &GroupController{db: NewMySqlDatabase(groupModel)}
|
||||
//groupModel.cache = cache.NewGroupCache(rdb, db, rockscache.Options{
|
||||
// DisableCacheRead: false,
|
||||
// StrongConsistency: true,
|
||||
//})
|
||||
//groupModel.mongo = mongoDB.NewMongoClient(mdb)
|
||||
//return &groupModel
|
||||
}
|
||||
|
||||
func (g *GroupController) Find(ctx context.Context, groupIDs []string) (groups []*mysql.Group, err error) {
|
||||
return g.cache.GetGroupsInfoFromCache(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupModel) Create(ctx context.Context, groups []*mysql.Group) error {
|
||||
func (g *GroupController) Create(ctx context.Context, groups []*mysql.Group) error {
|
||||
return g.db.Create(ctx, groups)
|
||||
}
|
||||
|
||||
func (g *GroupModel) Delete(ctx context.Context, groupIDs []string) error {
|
||||
func (g *GroupController) Delete(ctx context.Context, groupIDs []string) error {
|
||||
err := g.db.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.db.Delete(ctx, groupIDs, tx); err != nil {
|
||||
return err
|
||||
@ -57,11 +77,11 @@ func (g *GroupModel) Delete(ctx context.Context, groupIDs []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (g *GroupModel) Take(ctx context.Context, groupID string) (group *mysql.Group, err error) {
|
||||
func (g *GroupController) Take(ctx context.Context, groupID string) (group *mysql.Group, err error) {
|
||||
return g.cache.GetGroupInfoFromCache(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupModel) Update(ctx context.Context, groups []*mysql.Group) error {
|
||||
func (g *GroupController) Update(ctx context.Context, groups []*mysql.Group) error {
|
||||
err := g.db.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.db.Update(ctx, groups, tx); err != nil {
|
||||
return err
|
||||
|
@ -16,7 +16,6 @@ type GroupModelInterface interface {
|
||||
Update(ctx context.Context, groups []*Group) (err error)
|
||||
Find(ctx context.Context, groupIDs []string) (groups []*Group, err error)
|
||||
Take(ctx context.Context, groupID string) (group *Group, err error)
|
||||
DeleteTx(ctx context.Context, groupIDs []string) error
|
||||
|
||||
//mongo
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user