From 5083db9588937cd6634bf96190e7be8d079410bc Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 12 Sep 2023 15:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96redis=20=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battle/modelBattle.go | 9 ++++----- modules/comp_model.go | 2 +- modules/dragon/module.go | 3 +-- modules/enchant/api_ranklist.go | 2 +- modules/enchant/module.go | 2 +- modules/gourmet/api_getranduser.go | 3 +-- modules/hero/api_info.go | 3 +-- modules/hero/hero_test.go | 2 +- modules/hunting/api_ranklist.go | 2 +- modules/hunting/model_rank.go | 2 +- modules/hunting/module.go | 3 +-- modules/mail/module.go | 13 ++++++------- modules/modulebase.go | 6 +++--- modules/pagoda/api_challengeover.go | 3 +-- modules/pagoda/api_crossrank.go | 2 +- modules/pagoda/api_racechallengeover.go | 3 +-- modules/pagoda/model_rank.go | 2 +- modules/practice/module.go | 4 ++-- modules/sociaty/module.go | 2 +- modules/timer/module.go | 3 +-- modules/user/api_getserverdata.go | 3 +-- modules/user/module.go | 16 ++++++++-------- modules/viking/api_ranklist.go | 2 +- modules/viking/api_seasonrank.go | 2 +- modules/viking/model_rank.go | 2 +- modules/viking/module.go | 4 ++-- services/comp_gateroute.go | 2 +- sys/db/dbmodel.go | 13 +++++++++++-- 28 files changed, 57 insertions(+), 58 deletions(-) diff --git a/modules/battle/modelBattle.go b/modules/battle/modelBattle.go index c400d4bad..ea98524e4 100644 --- a/modules/battle/modelBattle.go +++ b/modules/battle/modelBattle.go @@ -11,7 +11,6 @@ import ( cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "math" - "time" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -77,7 +76,7 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon return } if req.Format != nil { - model := db.NewDBModel(comm.TableHero, time.Hour, conn) + model := db.NewDBModel(comm.TableHero, conn) record.Redflist = make([]*pb.DBBattleFormt, 1) record.Redflist[0] = &pb.DBBattleFormt{ Leadpos: req.Format.Leadpos, @@ -218,7 +217,7 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon Leadpos: req.Format.Leadpos, Team: make([]*pb.BattleRole, len(req.Format.Format)), } - model := db.NewDBModel(comm.TableHero, time.Hour, conn) + model := db.NewDBModel(comm.TableHero, conn) if user, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, @@ -366,7 +365,7 @@ func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBCon Leadpos: v.Leadpos, Team: make([]*pb.BattleRole, len(v.Format)), } - model := db.NewDBModel(comm.TableHero, time.Hour, conn) + model := db.NewDBModel(comm.TableHero, conn) //自己的英雄阵营 for i, v := range v.Format { if v != "" { @@ -625,7 +624,7 @@ func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBCo Leadpos: req.Format.Leadpos, Team: make([]*pb.BattleRole, len(req.Format.Format)), } - model := db.NewDBModel(comm.TableHero, time.Hour, conn) + model := db.NewDBModel(comm.TableHero, conn) if user, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, diff --git a/modules/comp_model.go b/modules/comp_model.go index ca054e2c6..9bfbd47bb 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -48,7 +48,7 @@ func (this *MCompModel) Start() (err error) { if conn, err = db.Local(); err != nil { return } - this.DBModel = db.NewDBModel(this.TableName, this.Expired, conn) + this.DBModel = db.NewDBModel(this.TableName, conn) return } diff --git a/modules/dragon/module.go b/modules/dragon/module.go index 9be518936..ed65eb9b0 100644 --- a/modules/dragon/module.go +++ b/modules/dragon/module.go @@ -11,7 +11,6 @@ import ( "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" - "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -145,7 +144,7 @@ func (this *Dragon) QueryDragonByTagAndOid(tag string, objId []string) (dragon [ return } dragon = make([]*pb.DBDragon, 0) - model = db.NewDBModel(this.modelDragon.TableName, time.Hour, conn) + model = db.NewDBModel(this.modelDragon.TableName, conn) result := make([]bson.M, 0) diff --git a/modules/enchant/api_ranklist.go b/modules/enchant/api_ranklist.go index 276c8c776..a4c0dba71 100644 --- a/modules/enchant/api_ranklist.go +++ b/modules/enchant/api_ranklist.go @@ -27,7 +27,7 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.EnchantRankList return // 参数校验失败直接返回 } conn, _ := db.Local() - dbModel := db.NewDBModel(comm.TableEnchantRank, 0, conn) + dbModel := db.NewDBModelByExpired(comm.TableEnchantRank, conn) if !req.Friend { var ( pipe *pipe.RedisPipe = this.module.modelEnchant.Redis.RedisPipe(context.TODO()) diff --git a/modules/enchant/module.go b/modules/enchant/module.go index 107938368..c2df44f3f 100644 --- a/modules/enchant/module.go +++ b/modules/enchant/module.go @@ -85,7 +85,7 @@ func (this *Enchant) CheckUserBaseEnchantInfo(uid string) (data []*pb.DBEnchantR func (this *Enchant) CheckRank(uid string, boosID int32, report *pb.BattleReport, userinfo *pb.DBUser, score int64) { conn_, _ := db.Cross() // 获取跨服数据库对象 - model := db.NewDBModel(comm.TableEnchantRank, 0, conn_) + model := db.NewDBModelByExpired(comm.TableEnchantRank, conn_) costTime := report.Costtime szLine := make([]*pb.LineUp, len(report.Info.Redflist[0].Team)) diff --git a/modules/gourmet/api_getranduser.go b/modules/gourmet/api_getranduser.go index 3001a36ae..429a6d9d7 100644 --- a/modules/gourmet/api_getranduser.go +++ b/modules/gourmet/api_getranduser.go @@ -7,7 +7,6 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/db" "go_dreamfactory/utils" - "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" @@ -71,7 +70,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa tag, _, b := utils.UIdSplit(session.GetUserId()) if b { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableHero, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableHero, conn) if _data, err1 := dbModel.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil { for _data.Next(context.TODO()) { temp := &pb.DBUser{} diff --git a/modules/hero/api_info.go b/modules/hero/api_info.go index 446acabe7..4b8e8250d 100644 --- a/modules/hero/api_info.go +++ b/modules/hero/api_info.go @@ -5,7 +5,6 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/db" "go_dreamfactory/utils" - "time" ) //参数校验 @@ -37,7 +36,7 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.HeroInfoReq) (errda if tag, _, ok := utils.UIdSplit(uid); ok { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableHero, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableHero, conn) for _, v := range req.HeroId { if v == "" { continue diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 66225c532..96a0a334b 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -91,7 +91,7 @@ func TimerStar() { if !db.IsCross() { conn, err := db.Cross() if err == nil { - model := db.NewDBModel(comm.TablePagodaRecord, 0, conn) + model := db.NewDBModel(comm.TablePagodaRecord, conn) //model.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete()) model.DB.DeleteMany(comm.TablePagodaRecord, bson.M{}, options.Delete()) for pos := 0; pos < comm.MaxRankNum; pos++ { diff --git a/modules/hunting/api_ranklist.go b/modules/hunting/api_ranklist.go index 0e9877d14..6a4905803 100644 --- a/modules/hunting/api_ranklist.go +++ b/modules/hunting/api_ranklist.go @@ -26,7 +26,7 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.HuntingRankList return // 参数校验失败直接返回 } conn, _ := db.Local() - dbModel := db.NewDBModel(comm.TableHuntingRank, 0, conn) + dbModel := db.NewDBModelByExpired(comm.TableHuntingRank, conn) if !req.Friend { var ( pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) diff --git a/modules/hunting/model_rank.go b/modules/hunting/model_rank.go index 722694d82..fed409267 100644 --- a/modules/hunting/model_rank.go +++ b/modules/hunting/model_rank.go @@ -63,7 +63,7 @@ func (this *ModelRank) getHuntingRankListByBossType(uid string, bossType int32) if err != nil { return nil } - model := db.NewDBModel(comm.TableHuntingRank, 0, conn) + model := db.NewDBModelByExpired(comm.TableHuntingRank, conn) err = model.GetList(uid, &ranks) if err != nil { diff --git a/modules/hunting/module.go b/modules/hunting/module.go index 7bcddac19..7e1ab9374 100644 --- a/modules/hunting/module.go +++ b/modules/hunting/module.go @@ -10,7 +10,6 @@ import ( "go_dreamfactory/sys/db" "math" "strconv" - "time" "github.com/go-redis/redis/v8" "go.mongodb.org/mongo-driver/bson/primitive" @@ -87,7 +86,7 @@ func (this *Hunting) CheckUserBaseHuntingInfo(uid string) (data []*pb.DBHuntingR func (this *Hunting) CheckRank(uid string, boosID int32, difficulty int32, report *pb.BattleReport) { conn_, _ := db.Cross() // 获取跨服数据库对象 userinfo := this.ModuleUser.GetUser(uid) - model := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_) + model := db.NewDBModel(comm.TableHuntingRank, conn_) costTime := report.Costtime szLine := make([]*pb.LineUp, len(report.Info.Redflist[0].Team)) diff --git a/modules/mail/module.go b/modules/mail/module.go index 0bbc84884..dc90b983a 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -9,7 +9,6 @@ import ( cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "go_dreamfactory/utils" - "time" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -71,7 +70,7 @@ func (this *Mail) SendNewMail(mail *pb.DBMailData, uid ...string) bool { tag, _, b := utils.UIdSplit(id) if b { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) mail.ObjId = primitive.NewObjectID().Hex() mail.Check = false mail.Reward = true @@ -147,7 +146,7 @@ func (this *Mail) Rpc_Mail(ctx context.Context, args *pb.DBMailData) (err error) tag, _, b := utils.UIdSplit(args.Uid) if b { if conn, err = db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) _, err = dbModel.DB.InsertOne(comm.TableMail, args) if err != nil { this.Error("Create Rpc_Mail failed", log.Field{Key: "uid", Value: args.Uid}, log.Field{Key: "err", Value: err.Error()}) @@ -201,7 +200,7 @@ func (this *Mail) SendMailByCid(session comm.IUserSession, cid string, res []*pb tag, _, b := utils.UIdSplit(session.GetUserId()) if b { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil { this.Errorf("InsertOne mail failed:%v", err) @@ -278,7 +277,7 @@ func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Para tag, _, b := utils.UIdSplit(uid) if b { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil { this.Errorf("InsertOne mail failed:%v", err) @@ -345,7 +344,7 @@ func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res tag, _, b := utils.UIdSplit(session.GetUserId()) if b { if conn, err := db.ServerDBConn(tag); err == nil { - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil { this.Errorf("InsertOne mail failed:%v", err) @@ -402,7 +401,7 @@ func (this *Mail) SendMailToUsers(uids []string, cid string, res []*cfg.Gameatn, Cid: cid, Param: param, } - dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableMail, conn) mail.ObjId = primitive.NewObjectID().Hex() mail.Check = false mail.Reward = true diff --git a/modules/modulebase.go b/modules/modulebase.go index fbdda3575..625662d02 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -535,7 +535,7 @@ func (this *ModuleBase) GetDBNodule(session comm.IUserSession, tableName string, return } } - model = db.NewDBModel(tableName, expired, conn) + model = db.NewDBModel(tableName, conn) return } @@ -553,7 +553,7 @@ func (this *ModuleBase) GetCrossDBModel(tableName string) (model *db.DBModel, er return } } - model = db.NewDBModel(tableName, time.Hour, conn) + model = db.NewDBModel(tableName, conn) return } @@ -575,7 +575,7 @@ func (this *ModuleBase) GetDBModelByUid(uid, tableName string) (model *db.DBMode return } } - model = db.NewDBModel(tableName, time.Hour, conn) + model = db.NewDBModel(tableName, conn) return } diff --git a/modules/pagoda/api_challengeover.go b/modules/pagoda/api_challengeover.go index f16fbb22a..eb3b6ab4b 100644 --- a/modules/pagoda/api_challengeover.go +++ b/modules/pagoda/api_challengeover.go @@ -5,7 +5,6 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/db" "strconv" - "time" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -166,7 +165,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal // 数据写到跨服中 if conn_, err := db.Cross(); err == nil { - dbModel := db.NewDBModel(comm.TablePagodaRecord, time.Hour, conn_) + dbModel := db.NewDBModel(comm.TablePagodaRecord, conn_) dbModel.AddList(uid, newData.Id, newData) } else { this.module.Errorf("db crosserr :%v", err) diff --git a/modules/pagoda/api_crossrank.go b/modules/pagoda/api_crossrank.go index 754ad0595..c615102a6 100644 --- a/modules/pagoda/api_crossrank.go +++ b/modules/pagoda/api_crossrank.go @@ -37,7 +37,7 @@ func (this *apiComp) CrossRaceRankList(session comm.IUserSession, req *pb.Pagoda if this.module.IsCross() { conn, _ := db.Local() - dbModel := db.NewDBModel(comm.TableRaceRecord, 0, conn) + dbModel := db.NewDBModel(comm.TableRaceRecord, conn) pipe = conn.Redis.RedisPipe(context.TODO()) tablename := "race" + strconv.Itoa(int(req.Raceid)) diff --git a/modules/pagoda/api_racechallengeover.go b/modules/pagoda/api_racechallengeover.go index ca094e83d..f0d7e78e9 100644 --- a/modules/pagoda/api_racechallengeover.go +++ b/modules/pagoda/api_racechallengeover.go @@ -6,7 +6,6 @@ import ( "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" "strconv" - "time" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -147,7 +146,7 @@ func (this *apiComp) ChallengeRaceOver(session comm.IUserSession, req *pb.Pagoda // 数据写到跨服中 if conn_, err := db.Cross(); err == nil { - dbModel := db.NewDBModel(comm.TableRaceRecord, time.Hour, conn_) + dbModel := db.NewDBModel(comm.TableRaceRecord, conn_) result := make([]*pb.DBRacePagodaRecord, 0) bRet := false dbModel.GetList(uid, &result) diff --git a/modules/pagoda/model_rank.go b/modules/pagoda/model_rank.go index 76debde2c..a4905ef67 100644 --- a/modules/pagoda/model_rank.go +++ b/modules/pagoda/model_rank.go @@ -43,7 +43,7 @@ func (this *ModelRank) getPagodaRankListByFloorid(uid string, cid int32) *pb.DBP } } else { if conn, err := db.Cross(); err == nil { - dbModel := db.NewDBModel(comm.TablePagodaRecord, 0, conn) + dbModel := db.NewDBModel(comm.TablePagodaRecord, conn) if err = dbModel.GetList(uid, &pagodaRank); err != nil { return nil } diff --git a/modules/practice/module.go b/modules/practice/module.go index 566075e96..f17a30b65 100644 --- a/modules/practice/module.go +++ b/modules/practice/module.go @@ -140,7 +140,7 @@ func (this *Practice) AddItems(session comm.IUserSession, items map[string]int32 this.Errorln(err) return } - model := db.NewDBModel(comm.TablePandata, time.Hour, conn) + model := db.NewDBModel(comm.TablePandata, conn) if err = model.Get(session.GetUserId(), room); err != nil && err != mgo.MongodbNil { this.Errorln(err) return @@ -401,7 +401,7 @@ func (this *Practice) RPC_ModulePracticeUnLockPillar(ctx context.Context, args * // 一键踢馆 (跨服) func (this *Practice) CleanUpNpc(uid string) { conn_, _ := db.Cross() // 获取跨服数据库对象 - model := db.NewDBModel(comm.TablePandata, time.Hour, conn_) + model := db.NewDBModel(comm.TablePandata, conn_) result := &pb.DBPracticeRoom{} if err := model.Get(uid, result); err != nil && err != mgo.MongodbNil { return diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 5cb199712..56234cb17 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -368,7 +368,7 @@ func (this *Sociaty) RpcUpdateUserTask(ctx context.Context, p *TaskParams, reply if err != nil { return err } - model := db.NewDBModel(comm.TableSociatyTask, 0, conn) + model := db.NewDBModel(comm.TableSociatyTask, conn) if err := model.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.modelSociatyTask.TableName, p.SociatyId, p.Uid), p.Data); err != nil { diff --git a/modules/timer/module.go b/modules/timer/module.go index 9fb34523e..88b1b4a46 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -7,7 +7,6 @@ import ( "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" "go_dreamfactory/sys/db" - "time" ) /* @@ -90,7 +89,7 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er return } } - model = db.NewDBModel(tableName, time.Hour, conn) + model = db.NewDBModel(tableName, conn) return } diff --git a/modules/user/api_getserverdata.go b/modules/user/api_getserverdata.go index 8ce21447a..df66bdd81 100644 --- a/modules/user/api_getserverdata.go +++ b/modules/user/api_getserverdata.go @@ -4,7 +4,6 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/db" - "time" "go.mongodb.org/mongo-driver/bson" ) @@ -20,7 +19,7 @@ func (this *apiComp) GetServerData(session comm.IUserSession, req *pb.UserGetSer } if conn, err := db.Cross(); err == nil { - dbModel := db.NewDBModel(comm.TableHero, time.Hour, conn) + dbModel := db.NewDBModel(comm.TableHero, conn) if _data := dbModel.DB.FindOne("serverdata", bson.M{}); _data != nil { _data.Decode(rsp.Data) } else { diff --git a/modules/user/module.go b/modules/user/module.go index be412fcb8..0317dc4fd 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -218,7 +218,7 @@ func (this *User) CrossUserOnlineList() ([]*pb.CacheUser, error) { if err != nil { return nil, err } - model := db.NewDBModel(comm.TableSession, 0, conn) + model := db.NewDBModelByExpired(comm.TableSession, conn) var cache []*pb.CacheUser if err := model.GetList(comm.RDS_EMPTY, &cache); err != nil { return nil, err @@ -232,7 +232,7 @@ func (this *User) crossUser(uid string) (*pb.CacheUser, error) { if err != nil { return nil, err } - model := db.NewDBModel(comm.TableSession, 0, conn) + model := db.NewDBModelByExpired(comm.TableSession, conn) cache := &pb.CacheUser{} if err := model.Get(uid, cache); err != nil { return nil, err @@ -280,7 +280,7 @@ func (this *User) RpcCreateSociaty(ctx context.Context, req *pb.RPCGeneralReqA2, if err != nil { return err } - model := db.NewDBModel(comm.TableSociaty, 0, conn) + model := db.NewDBModel(comm.TableSociaty, conn) sociaty := &pb.DBSociaty{} _id := primitive.NewObjectID().Hex() @@ -800,7 +800,7 @@ func (this *User) getUserFromRemoteDb(uid string, rsp *pb.DBUser) error { if err != nil { return err } - model := db.NewDBModel(comm.TableUser, 0, conn) + model := db.NewDBModel(comm.TableUser, conn) if err := model.Get(uid, rsp); err != nil { this.Errorln("Get User:", err) return err @@ -817,7 +817,7 @@ func (this *User) getUserExpandFromRemoteDb(uid string, rsp *pb.DBUserExpand) er if err != nil { return err } - model := db.NewDBModel(comm.TableUserExpand, 0, conn) + model := db.NewDBModel(comm.TableUserExpand, conn) if err := model.Get(uid, rsp); err != nil { return err @@ -834,7 +834,7 @@ func (this *User) changeUserExpandFromRemoteDb(uid string, data map[string]inter if err != nil { return err } - model := db.NewDBModel(comm.TableUserExpand, 0, conn) + model := db.NewDBModel(comm.TableUserExpand, conn) if err := model.Change(uid, data); err != nil { return err @@ -873,7 +873,7 @@ func (this *User) RpcGetAllOnlineUser(ctx context.Context, args *pb.EmptyReq, re if err != nil { return err } - model := db.NewDBModel(comm.TableSession, 0, conn) + model := db.NewDBModelByExpired(comm.TableSession, conn) var cache []*pb.CacheUser if err := model.GetList(comm.RDS_EMPTY, &cache); err != nil { return err @@ -891,7 +891,7 @@ func (this *User) RpcGetCrossUserSession(ctx context.Context, req *pb.UIdReq, re if err != nil { return err } - model := db.NewDBModel(comm.TableSession, 0, conn) + model := db.NewDBModelByExpired(comm.TableSession, conn) if err := model.GetListObj(comm.RDS_EMPTY, req.Uid, reply); err != nil { if err != mongo.ErrNoDocuments { return err diff --git a/modules/viking/api_ranklist.go b/modules/viking/api_ranklist.go index 8ffc1975b..5939028b3 100644 --- a/modules/viking/api_ranklist.go +++ b/modules/viking/api_ranklist.go @@ -32,7 +32,7 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.VikingRankListR } conn, _ := db.Local() - dbModel := db.NewDBModel(comm.TableVikingRank, 0, conn) + dbModel := db.NewDBModelByExpired(comm.TableVikingRank, conn) if !req.Friend { var ( pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) diff --git a/modules/viking/api_seasonrank.go b/modules/viking/api_seasonrank.go index 766ae707b..2ed4f262d 100644 --- a/modules/viking/api_seasonrank.go +++ b/modules/viking/api_seasonrank.go @@ -55,7 +55,7 @@ func (this *apiComp) SeasonRank(session comm.IUserSession, req *pb.VikingSeasonR } } - dbModel := db.NewDBModel(comm.TableVikingSRank, 0, conn) + dbModel := db.NewDBModelByExpired(comm.TableVikingSRank, conn) pipe = conn.Redis.RedisPipe(context.TODO()) rd = pipe.ZRevRange("vSeasonRank"+strconv.Itoa(int(req.BoosType)), 0, comm.MaxRankList) diff --git a/modules/viking/model_rank.go b/modules/viking/model_rank.go index 698eb1c88..b5b7d55c5 100644 --- a/modules/viking/model_rank.go +++ b/modules/viking/model_rank.go @@ -61,7 +61,7 @@ func (this *ModelRank) getVikingRankListByBossType(uid string, bossType int32) * if err != nil { return nil } - model := db.NewDBModel(comm.TableVikingRank, 0, conn) + model := db.NewDBModelByExpired(comm.TableVikingRank, conn) ranks := make([]*pb.DBVikingRank, 0) err = model.GetList(uid, &ranks) if err != nil { diff --git a/modules/viking/module.go b/modules/viking/module.go index 9a5279d84..6ec4dcce1 100644 --- a/modules/viking/module.go +++ b/modules/viking/module.go @@ -107,7 +107,7 @@ func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, report return } userinfo := this.ModuleUser.GetUser(uid) - model := db.NewDBModel(comm.TableVikingRank, 0, conn_) + model := db.NewDBModelByExpired(comm.TableVikingRank, conn_) costTime := report.Costtime szLine := make([]*pb.LineUp, len(report.Info.Redflist[0].Team)) @@ -309,7 +309,7 @@ func (this *Viking) CheckSeasonRank(uid string, boosID int32, difficulty int32, } userinfo := this.ModuleUser.GetUser(uid) - model := db.NewDBModel(comm.TableVikingSRank, 0, conn_) + model := db.NewDBModelByExpired(comm.TableVikingSRank, conn_) // 写入排行榜 objID := "" diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index cc708a274..5669a14ed 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -187,7 +187,7 @@ func (this *SCompGateRoute) NoticeUserLogin(ctx context.Context, args *pb.Notice log.Errorf("[RPC] NoticeUserLogin err: %v", err) return err } - model := db.NewDBModel(comm.TableSession, 0, conn) + model := db.NewDBModelByExpired(comm.TableSession, conn) user := &pb.CacheUser{ Uid: args.UserId, SessionId: args.UserSessionId, diff --git a/sys/db/dbmodel.go b/sys/db/dbmodel.go index 78debdb25..b25c342ad 100644 --- a/sys/db/dbmodel.go +++ b/sys/db/dbmodel.go @@ -38,10 +38,19 @@ const ( DB_ModelTable core.SqlTable = "model_log" ) -func NewDBModel(tableName string, expired time.Duration, conn *DBConn) *DBModel { +func NewDBModel(tableName string, conn *DBConn) *DBModel { return &DBModel{ TableName: tableName, - Expired: expired, + Expired: time.Minute * 15, + conn: conn, + Redis: conn.Redis, + DB: conn.Mgo, + } +} +func NewDBModelByExpired(tableName string, conn *DBConn) *DBModel { + return &DBModel{ + TableName: tableName, + Expired: 0, conn: conn, Redis: conn.Redis, DB: conn.Mgo,