fix: 修复排行榜未能正确加载的问题。

main
NorthLan 3 years ago
parent 66ee7ea63a
commit 9f4cc52b62

@ -76,9 +76,17 @@ func InitRankJob(svcCtx *svc.ServiceContext) {
func (j *Job) initJob() { func (j *Job) initJob() {
logx.Info("开启排行榜服务...") logx.Info("开启排行榜服务...")
j.initByType(model.RankTypeDamage) j.initByType(model.RankTypeDamage)
j.initByType(model.RankTypeDeDamage)
j.initByType(model.RankTypeGeneral) j.initByType(model.RankTypeGeneral)
j.initByType(model.RankTypeDeGeneral)
j.initByType(model.RankTypeKillUnit) j.initByType(model.RankTypeKillUnit)
j.initByType(model.RankTypeDeKillUnit)
j.initByType(model.RankTypeKillPlayer) j.initByType(model.RankTypeKillPlayer)
j.initByType(model.RankTypeDeKillPlayer)
j.initByType(model.RankTypeWin)
j.initByType(model.RankTypeLost)
j.initByType(model.RankTypeFirstBlood)
j.initByType(model.RankTypeDeFirstBlood)
// job read and update // job read and update
c := cron.New() c := cron.New()
@ -213,6 +221,10 @@ func (j *Job) initByType(rankType int32) {
if err != nil { if err != nil {
return return
} }
rankZSet, _, err := j.getRankInstanceAndScoreType(rankType)
if err != nil {
return
}
for _, user := range list { for _, user := range list {
// 缓存用户信息 // 缓存用户信息
j.userCache.Add(user.UserId, CachedUserInfo{ j.userCache.Add(user.UserId, CachedUserInfo{
@ -220,16 +232,7 @@ func (j *Job) initByType(rankType int32) {
Username: user.PUname, Username: user.PUname,
Avatar: user.PAvatar, Avatar: user.PAvatar,
}) })
switch rankType { rankZSet.Add(user.UserId, int32(user.Score))
case model.RankTypeDamage:
j.damageRank.Add(user.UserId, int32(user.Score))
case model.RankTypeGeneral:
j.generalRank.Add(user.UserId, int32(user.Score))
case model.RankTypeKillUnit:
j.killUnitRank.Add(user.UserId, int32(user.Score))
case model.RankTypeKillPlayer:
j.killPlayerRank.Add(user.UserId, int32(user.Score))
}
} }
} }

@ -25,8 +25,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
Logger: logger.New( Logger: logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{ logger.Config{
SlowThreshold: 1 * time.Second, SlowThreshold: 2 * time.Second,
LogLevel: logger.Info, LogLevel: logger.Warn,
IgnoreRecordNotFoundError: true, IgnoreRecordNotFoundError: true,
Colorful: true, Colorful: true,
}, },

Loading…
Cancel
Save