diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go index bc51df2fa..6b4c7a99e 100644 --- a/modules/user/model_expand.go +++ b/modules/user/model_expand.go @@ -10,6 +10,7 @@ import ( "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) // 记录一些扩展数据 @@ -22,6 +23,9 @@ func (this *ModelExpand) Init(service core.IService, module core.IModule, comp c this.TableName = comm.TableUserExpand err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } @@ -35,7 +39,7 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err } else { if err = model.Get(uid, result); err != nil && mongo.ErrNoDocuments != err { this.module.Error("Cross Get", log.Fields{"uid": uid}) - return result,err + return result, err } } } else { diff --git a/modules/user/model_setting.go b/modules/user/model_setting.go index bc12aafd9..28b943d26 100644 --- a/modules/user/model_setting.go +++ b/modules/user/model_setting.go @@ -12,6 +12,8 @@ import ( "time" "github.com/spf13/cast" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelSetting struct { @@ -23,6 +25,9 @@ func (this *ModelSetting) Init(service core.IService, module core.IModule, comp this.TableName = comm.TableSetting err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go index 15d462c76..96cd180af 100644 --- a/modules/user/model_sign.go +++ b/modules/user/model_sign.go @@ -11,6 +11,7 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) // 签到 @@ -23,6 +24,9 @@ func (this *ModelSign) Init(service core.IService, module core.IModule, comp cor this.TableName = comm.TableSign err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index cf145d411..46e93ad64 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -17,6 +17,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelUser struct { @@ -32,6 +33,14 @@ func (this *ModelUser) Init(service core.IService, module core.IModule, comp cor this.EventApp = event_v2.NewApp() this.EventApp.Listen(comm.EventUserChanged, this.ChangeExp) this.EventApp.Listen(comm.EventUserChanged, this.ChangeLevel) + // 通过uid创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "name", Value: bsonx.Int32(1)}}, + }) return }