每10分钟刷新排行榜前一千名玩家的用户数据
This commit is contained in:
parent
bdb83f9da7
commit
3c034fb296
@ -27,4 +27,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
|
|||||||
...data,
|
...data,
|
||||||
...enemy
|
...enemy
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JJCFun.checkUpdatePlayer()
|
||||||
|
|
||||||
}
|
}
|
@ -87,6 +87,45 @@ export class JJCFun {
|
|||||||
return rankList
|
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[]
|
* 获取指定范围排名的用户,仅返回uid[]
|
||||||
* @param min
|
* @param min
|
||||||
|
Loading…
Reference in New Issue
Block a user