每10分钟刷新排行榜前一千名玩家的用户数据

This commit is contained in:
dy 2023-12-27 17:53:32 +08:00
parent bdb83f9da7
commit 3c034fb296
2 changed files with 43 additions and 1 deletions

View File

@ -27,4 +27,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
...data,
...enemy
});
}
JJCFun.checkUpdatePlayer()
}

View File

@ -87,6 +87,45 @@ export class JJCFun {
return rankList
}
/**
* 10
* @param min
* @param max
* @param uTimeOffset
* @param isUpdate
*/
static async checkUpdatePlayer(min: number = 0, max: number = 1000, uTimeOffset: number = 600, isUpdate: boolean = true) {
// 获取指定排名用户uid
let sortInfo = await this.getRankListUid(min, max)
if (!sortInfo.length) return []
let updateArr = []
let users = await G.redis.hGetAll('rank:jjc:data')
for (let i = 0; i < sortInfo.length; i++) {
let uid = sortInfo[i]
let rankInfo = users[uid]
if (!rankInfo?.player) continue
// 比对utime判断是否更新数据
if (!rankInfo.player.isNpc) {
if (!rankInfo.utime || (rankInfo.utime && rankInfo.utime < (G.time - uTimeOffset))) {
updateArr.push(rankInfo)
}
}
}
// 更新数据
if (isUpdate && updateArr.length > 0) {
let playerArrInfo = await G.mongodb.collection("user").find({uid: {$in: updateArr.map(i => i.uid)}}).toArray()
for (let i = 0; i < playerArrInfo.length; i++) {
let playerInfo = playerArrInfo[i]
let index = updateArr.findIndex(x => x.player.uid == playerInfo.uid)
updateArr[index].player = playerInfo
updateArr[index].utime = G.time
this.updatePlayerData(playerInfo.uid, updateArr[index]);
}
}
}
/**
* uid[]
* @param min