diff options
author | mat-1 <github@matdoes.dev> | 2021-04-08 18:10:15 +0000 |
---|---|---|
committer | mat-1 <github@matdoes.dev> | 2021-04-08 18:10:15 +0000 |
commit | ddefc69df40827fe04902ab2da4baa4da3db96d5 (patch) | |
tree | 72557d2702f76553768602113a24506dc72b1422 /build | |
parent | ddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d (diff) | |
download | skyblock-api-ddefc69df40827fe04902ab2da4baa4da3db96d5.tar.gz skyblock-api-ddefc69df40827fe04902ab2da4baa4da3db96d5.tar.bz2 skyblock-api-ddefc69df40827fe04902ab2da4baa4da3db96d5.zip |
Compiled TS into JS
Diffstat (limited to 'build')
-rw-r--r-- | build/database.js | 17 | ||||
-rw-r--r-- | build/index.js | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/build/database.js b/build/database.js index 647c853..3076469 100644 --- a/build/database.js +++ b/build/database.js @@ -204,6 +204,8 @@ async function getApplicableAttributes(member) { } /** Update the member's leaderboard data on the server if applicable */ async function updateDatabaseMember(member, profile) { + if (_1.debug) + console.log('updateDatabaseMember', member.username); if (!client) return; // the db client hasn't been initialized // the member's been updated too recently, just return @@ -217,7 +219,11 @@ async function updateDatabaseMember(member, profile) { await constants.addCollections(member.collections.map(coll => coll.name)); await constants.addSkills(member.skills.map(skill => skill.name)); await constants.addZones(member.visited_zones.map(zone => zone.name)); + if (_1.debug) + console.log('done constants..'); const leaderboardAttributes = await getApplicableAttributes(member); + if (_1.debug) + console.log('done getApplicableAttributes..', leaderboardAttributes); await memberLeaderboardsCollection.updateOne({ uuid: member.uuid, profile: profile.uuid @@ -279,14 +285,15 @@ async function removeBadMemberLeaderboardAttributes() { } } /** Fetch all the leaderboards, used for caching. Don't call this often! */ -async function fetchAllLeaderboards() { +async function fetchAllLeaderboards(fast) { const leaderboards = await fetchAllMemberLeaderboardAttributes(); // shuffle so if the application is restarting many times itll still be useful if (_1.debug) console.log('Caching leaderboards!'); for (const leaderboard of util_1.shuffle(leaderboards)) { - // wait 2 seconds so it doesnt use as much ram - await util_1.sleep(2 * 1000); + if (!fast) + // wait 2 seconds so it doesnt use as much ram + await util_1.sleep(2 * 1000); await fetchMemberLeaderboard(leaderboard); } if (_1.debug) @@ -296,7 +303,7 @@ connect().then(() => { // when it connects, cache the leaderboards and remove bad members removeBadMemberLeaderboardAttributes(); // cache leaderboards on startup so its faster later on - fetchAllLeaderboards(); - // cache leaderboard players again every hour + fetchAllLeaderboards(true); + // cache leaderboard players again every 4 hours setInterval(fetchAllLeaderboards, 4 * 60 * 60 * 1000); }); diff --git a/build/index.js b/build/index.js index 536b43e..e547a72 100644 --- a/build/index.js +++ b/build/index.js @@ -9,7 +9,7 @@ const express_1 = __importDefault(require("express")); const database_1 = require("./database"); const express_rate_limit_1 = __importDefault(require("express-rate-limit")); const app = express_1.default(); -exports.debug = false; +exports.debug = true; // 500 requests over 5 minutes const limiter = express_rate_limit_1.default({ windowMs: 60 * 1000 * 5, |