🐞 fix(排行榜): 排行榜显示不查全部玩家只显示部分玩家

This commit is contained in:
luying
2023-05-06 17:59:16 +08:00
parent 76877348ba
commit 190897d711
3 changed files with 18 additions and 7 deletions

View File

@@ -94,7 +94,7 @@ export class RoleHandler {
if (!redisKey) return resResult(STATUS.WRONG_PARMS);
let r = new Rank(redisKey, { serverId, hid });
let ranks = await r.getRankByRange();
let ranks = await r.getRankByRange(200, 0);
return resResult(STATUS.SUCCESS, {
type, hid, ranks

View File

@@ -722,7 +722,7 @@ export class Rank {
}
public async getRankListWithMyRank(myId: myIdInter, isReverse = true) {
let ranks = await this.getRankByRange('+inf', '-inf', isReverse);
let ranks = await this.getRankByRange(1000, 0, isReverse);
let newRanks = [], newMyRank: any;
let myRank = ranks.find(cur => {
return cur.isMyInfo(myId);
@@ -745,13 +745,16 @@ export class Rank {
* @param from
* @param to
*/
public async getRankDataByRankWithoutDetail(from: number | string = '+inf', to: number | string = '-inf') {
public async getRankDataByRankWithoutDetail(from: number | '+inf' = '+inf', to: number | '-inf' = '-inf') {
let key = this.keyName.getName();
if (this.isUnion) {
key = await this.generateUnionRank();
}
const rankFromDb = await redisClient().zrevrangebyscoreAsync(key, from, to, "WITHSCORES");
const rankFromDb = (from == '+inf' && to == '-inf')?
(await redisClient().zrevrangebyscoreAsync(key, from, to, "WITHSCORES")):
(await redisClient().zrevrangeAsync(key, <number>from, <number>to, "WITHSCORES"))
;
let ranks: { rank: number, myId: {roleId?: string, guildCode?: string, hid?: number}, scores: number[] }[] = [];
let num = 0;
@@ -777,8 +780,14 @@ export class Rank {
}
const rankFromDb = isReverse?
(await redisClient().zrevrangebyscoreAsync(key, max, min, "WITHSCORES")):
(await redisClient().zrangebyscoreAsync(key, min, max, "WITHSCORES"));
((max == '+inf' && min == '-inf')?
(await redisClient().zrevrangebyscoreAsync(key, max, min, "WITHSCORES")):
(await redisClient().zrevrangeAsync(key, <number>min, <number>max, "WITHSCORES"))
):
((max == '+inf' && min == '-inf')?
(await redisClient().zrangebyscoreAsync(key, min, max, "WITHSCORES")):
(await redisClient().zrangeAsync(key, <number>min, <number>max, "WITHSCORES"))
)
let num = 0;
for (let ii = 0; ii < rankFromDb.length; ii += 2) {
@@ -1244,7 +1253,7 @@ export async function getGeneralRank(role: RoleType & { rankReceived: number[] }
return dic && dic.rankId == id;
});
let r = new Rank(redisKey, { serverId }, false, 1);
let ranks = await r.getRankByRange('+inf', '-inf', id != RANK_TYPE.LADDER);
let ranks = await r.getRankByRange(1, 0, id != RANK_TYPE.LADDER);
// if (ranks.length > 0) {
let param = new GeneralRankParam(id, ranks[0], general, received);
result.push({...param, general});