From 1c7876e3571f528b218f9f0cf1cca33b2788fa0c Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Tue, 1 Oct 2024 01:23:26 +0200 Subject: [PATCH] Just skip out the official server once out of twice This is done to stay under the /api/user/memory ratelimit of 1440/day. We have to cycle through each shard because the rate limits are per-account. --- src/pushStats/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pushStats/index.js b/src/pushStats/index.js index 7bfe95e..7fe2d46 100644 --- a/src/pushStats/index.js +++ b/src/pushStats/index.js @@ -65,22 +65,22 @@ class ManageStats { */ async handleUsers(host, hostUsers) { console.log(`[${host}] Handling Users`); + const now = new Date(); + + const beginningOfMinute = now.getSeconds() < 15; + if (host === 'screeps.com' && !beginningOfMinute) { + console.log(`[${host}] not the right time to get stats, skipping`); + return; + } - const beginningOfMinute = new Date().getSeconds() < 15; /** @type {(Promise)[]} */ const getStatsFunctions = []; for (const user of hostUsers) { try { if (user.host !== host) continue; - const rightMinuteForShard = new Date().getMinutes() % user.shards.length === 0; - const shouldContinue = !beginningOfMinute || !rightMinuteForShard; - if (user.type === 'mmo' && shouldContinue) continue; - if (user.type === 'season' && shouldContinue) continue; - - for (const shard of user.shards) { - getStatsFunctions.push(this.getStats(user, shard)); - } + const shard = user.shards[now.getMinutes() % user.shards.length]; + getStatsFunctions.push(this.getStats(user, shard)); } catch (error) { logger.error(error); }