From 7ec319f40d66213ee83b5fb41bcced42526fb1d9 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 5 Dec 2022 10:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8A=A0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/model_expand.go | 6 +++++- modules/user/model_setting.go | 5 +++++ modules/user/model_sign.go | 4 ++++ modules/user/model_user.go | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) 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 }