Skip to content

Commit

Permalink
Just skip out the official server once out of twice
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tiennou committed Sep 30, 2024
1 parent 12a2fc1 commit 1c7876e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/pushStats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>)[]} */
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);
}
Expand Down

0 comments on commit 1c7876e

Please sign in to comment.