mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-15 23:29:23 +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/mongoDB"
|
||||||
"Open_IM/pkg/common/db/mysql"
|
"Open_IM/pkg/common/db/mysql"
|
||||||
"context"
|
"context"
|
||||||
"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"
|
||||||
@ -19,32 +19,52 @@ type GroupInterface interface {
|
|||||||
Take(ctx context.Context, groupID string) (group *mysql.Group, err error)
|
Take(ctx context.Context, groupID string) (group *mysql.Group, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupModel struct {
|
type GroupController struct {
|
||||||
db mysql.GroupModelInterface
|
db DataBase
|
||||||
cache *cache.GroupCache
|
cache *cache.GroupCache
|
||||||
mongo *mongoDB.Client
|
mongo *mongoDB.Client
|
||||||
}
|
}
|
||||||
|
type DataBase interface {
|
||||||
func NewGroupModel(db mysql.GroupModelInterface, rdb redis.UniversalClient, mdb *mongo.Client) *GroupModel {
|
Find(ctx context.Context, groupIDs []string) (groups []*mysql.Group, err error)
|
||||||
var groupModel GroupModel
|
Create(ctx context.Context, groups []*mysql.Group) error
|
||||||
groupModel.db = db
|
Delete(ctx context.Context, groupIDs []string) error
|
||||||
groupModel.cache = cache.NewGroupCache(rdb, db, rockscache.Options{
|
Take(ctx context.Context, groupID string) (group *mysql.Group, err error)
|
||||||
DisableCacheRead: false,
|
DeleteTx(ctx context.Context, groupIDs []string) error
|
||||||
StrongConsistency: true,
|
}
|
||||||
})
|
type MySqlDatabase struct {
|
||||||
groupModel.mongo = mongoDB.NewMongoClient(mdb)
|
mysql.GroupModelInterface
|
||||||
return &groupModel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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)
|
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 {
|
err := g.db.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
if err := g.db.Delete(ctx, groupIDs, tx); err != nil {
|
if err := g.db.Delete(ctx, groupIDs, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -57,11 +77,11 @@ func (g *GroupModel) Delete(ctx context.Context, groupIDs []string) error {
|
|||||||
return err
|
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)
|
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 {
|
err := g.db.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
if err := g.db.Update(ctx, groups, tx); err != nil {
|
if err := g.db.Update(ctx, groups, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -16,7 +16,6 @@ type GroupModelInterface interface {
|
|||||||
Update(ctx context.Context, groups []*Group) (err error)
|
Update(ctx context.Context, groups []*Group) (err error)
|
||||||
Find(ctx context.Context, groupIDs []string) (groups []*Group, err error)
|
Find(ctx context.Context, groupIDs []string) (groups []*Group, err error)
|
||||||
Take(ctx context.Context, groupID string) (group *Group, err error)
|
Take(ctx context.Context, groupID string) (group *Group, err error)
|
||||||
DeleteTx(ctx context.Context, groupIDs []string) error
|
|
||||||
|
|
||||||
//mongo
|
//mongo
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user