From ef65397d8a955a1e68ef088f723fc590827b79ad Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 25 Jul 2023 19:14:38 +0800 Subject: [PATCH] 1 --- server/game2006service/tasks/rankings.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/server/game2006service/tasks/rankings.js b/server/game2006service/tasks/rankings.js index 932a6442..9fcd80ca 100644 --- a/server/game2006service/tasks/rankings.js +++ b/server/game2006service/tasks/rankings.js @@ -6,6 +6,8 @@ const Redis = require('../services/redis'); const RANKING_KEY = 'game2006api:'; const LAST_IDX = 'userLastIdx'; +const BASE_SCORE = 2800; + class Rankings { async start() { @@ -28,7 +30,7 @@ class Rankings { await Redis.del(RANKING_KEY + 'account') await Redis.del(RANKING_KEY + 'ranking') await this.calcRanking(); - console.log("跟新rank榜单") + console.log("刷新rank榜单") }else { await this.calcRanking(); console.log("生成rank榜单") @@ -49,29 +51,23 @@ class Rankings { // 从user表中遍历所有用户,每次取1000个用户,逐步加入到排序表中 let sorted = []; let lastIdx = 0; - while(lastIdx>=0) { + while (lastIdx>=0) { const result = await this.getRecords(conn, lastIdx, 1000); lastIdx = result.lastIdx; if (lastIdx != -1) { this.recordsSort(sorted, result.records) } + console.log(lastIdx, sorted); } await this.pushResultToRedis(sorted); - - // let rankList = await this.pushRankingResult(sorted); - // console.log(rankList); - - //存储到redis中 - // let listJson = JSON.stringify(rankList); - // Redis.set(RANKING_KEY + "rank",listJson); console.log("calc ranking end"); - } } //增加排名列 async pushResultToRedis(sorted) { + console.log(sorted); let rankingList = []; await utils.serial( sorted, @@ -112,7 +108,7 @@ class Rankings { recordsSort(sorted, records) { // 根据分数加入到排序表中 for (let element of records) { - if (element.score>2800) { + if (element.score>BASE_SCORE) { if (sorted.length >= 10000){ if (element.score >= sorted[sorted.length - 1].score){ this._recordsSort(sorted,element);