This commit is contained in:
liwei1dao 2022-06-14 15:32:29 +08:00
commit 8ff4813033
4 changed files with 40 additions and 7 deletions

View File

@ -5,9 +5,9 @@ import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
@ -18,7 +18,7 @@ const (
)
type DB_Comp struct {
cbase.ModuleCompBase
modules.MComp_DBComp
mgo mgo.ISys
}

View File

@ -9,12 +9,12 @@ import (
type DBService_Comp struct {
cbase.ModuleCompBase
task chan string
DB_Comp
module *Model
}
func (this *DBService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options)
this.module = module.(*Model)
return
}
@ -27,9 +27,9 @@ func (this *DBService_Comp) run() {
for {
select {
case v := <-this.task:
this.Model_UpdateUserDataByUid(v)
this.module.DB().(*DB_Comp).Model_UpdateUserDataByUid(v)
case <-time.After(time.Second):
this.Model_UpdateDBByLog()
this.module.DB().(*DB_Comp).Model_UpdateDBByLog()
}
}
}

View File

@ -2,10 +2,16 @@ package cache_test
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db"
"os"
"testing"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
//测试环境下初始化db和cache 系统
@ -19,6 +25,33 @@ func TestMain(m *testing.M) {
return
}
_mail := &pb.DB_MailData{
UserId: "uid123",
Title: "系统邮件",
Contex: "恭喜获得专属礼包一份",
CreateTime: uint64(time.Now().Unix()),
DueTime: uint64(time.Now().Unix()) + 30*24*3600,
Check: false,
Reward: false,
}
//db.InsertModelLogs("mail", "uid123", _mail)
//InsertModelLogs("mail", "uid123", _mail)
data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(),
UID: "uid123",
Act: string(comm.LogHandleType_Insert),
}
data.D = append(data.D, "mail") // D[0]
data.D = append(data.D, _mail) // D[1]
for i := 0; i < 100000; i++ {
_, err1 := db.Defsys.Mgo().InsertOne("model", data)
if err1 != nil {
log.Errorf("insert model db err %v", err1)
}
}
defer os.Exit(m.Run())
}