From 54627ec4f1ff12c9bb20c80b1cebf6f4698aced4 Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 24 Sep 2022 15:04:56 +0200 Subject: [PATCH] finalize ranking change --- src/core/Ranks.js | 29 ++++++----------------------- src/data/redis/ranks.js | 4 ++-- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/core/Ranks.js b/src/core/Ranks.js index a1500f8..af9fed0 100644 --- a/src/core/Ranks.js +++ b/src/core/Ranks.js @@ -53,17 +53,14 @@ class Ranks { }; await Ranks.updateRanking(); } catch (err) { + // eslint-disable-next-line no-console console.error(`Error initialize ranks: ${err.message}`); } setInterval(Ranks.updateRanking, 5 * MINUTE); + HourlyCron.hook(Ranks.setHourlyRanking); DailyCron.hook(Ranks.setDailyRanking); - setInterval(Ranks.setHourlyRanking, 5 * MINUTE); - //HourlyCron.hook(Ranks.setHourlyRanking); } - /* - * get daily and total ranking from database - */ static async updateRanking() { // only main shard does it if (!socketEvents.amIImportant()) { @@ -89,14 +86,11 @@ class Ranks { return ret; } - /* - * get online counter stats, - * list of users online per hour - */ static async hourlyUpdateRanking() { const onlineStats = await getOnlineUserStats(); const cHistStats = await getCountryDailyHistory(); const histStats = await getTopDailyHistory(); + histStats.users = await populateRanking(histStats.users); const ret = { onlineStats, cHistStats, @@ -109,9 +103,6 @@ class Ranks { return ret; } - /* - * get prevTop from database - */ static async dailyUpdateRanking() { const prevTop = await populateRanking( await getPrevTop(), @@ -126,21 +117,13 @@ class Ranks { return ret; } - /* - * get and store amount of online users into stats - */ static async setHourlyRanking() { if (!socketEvents.amIImportant()) { return; } - let amount; - try { - amount = socketEvents.onlineCounter.total; - await storeOnlinUserAmount(amount); - await Ranks.hourlyUpdateRanking(); - } catch (err) { - console.error(`error on hourly ranking: ${err.message} / ${amount}`); - } + const amount = socketEvents.onlineCounter.total; + await storeOnlinUserAmount(amount); + await Ranks.hourlyUpdateRanking(); } /* diff --git a/src/data/redis/ranks.js b/src/data/redis/ranks.js index ce79df9..d3b7d57 100644 --- a/src/data/redis/ranks.js +++ b/src/data/redis/ranks.js @@ -106,8 +106,8 @@ export async function storeOnlinUserAmount(amount) { * get list of online counters */ export async function getOnlineUserStats() { - const onlineStats = await client.lRange(ONLINE_CNTR_KEY, 0, -1); - console.log('STAAATTTSS', onlineStats); + let onlineStats = await client.lRange(ONLINE_CNTR_KEY, 0, -1); + onlineStats = onlineStats.map((s) => Number(s)); return onlineStats; }