数据库加索引
This commit is contained in:
parent
90a4964e11
commit
7ec319f40d
@ -10,6 +10,7 @@ import (
|
|||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"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
|
this.TableName = comm.TableUserExpand
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.module = module.(*User)
|
this.module = module.(*User)
|
||||||
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +39,7 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err
|
|||||||
} else {
|
} else {
|
||||||
if err = model.Get(uid, result); err != nil && mongo.ErrNoDocuments != err {
|
if err = model.Get(uid, result); err != nil && mongo.ErrNoDocuments != err {
|
||||||
this.module.Error("Cross Get", log.Fields{"uid": uid})
|
this.module.Error("Cross Get", log.Fields{"uid": uid})
|
||||||
return result,err
|
return result, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelSetting struct {
|
type ModelSetting struct {
|
||||||
@ -23,6 +25,9 @@ func (this *ModelSetting) Init(service core.IService, module core.IModule, comp
|
|||||||
this.TableName = comm.TableSetting
|
this.TableName = comm.TableSetting
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.module = module.(*User)
|
this.module = module.(*User)
|
||||||
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"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
|
this.TableName = comm.TableSign
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.module = module.(*User)
|
this.module = module.(*User)
|
||||||
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelUser struct {
|
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 = event_v2.NewApp()
|
||||||
this.EventApp.Listen(comm.EventUserChanged, this.ChangeExp)
|
this.EventApp.Listen(comm.EventUserChanged, this.ChangeExp)
|
||||||
this.EventApp.Listen(comm.EventUserChanged, this.ChangeLevel)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user