1
This commit is contained in:
parent
580b5228dd
commit
ef65397d8a
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user