From ddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 8 Apr 2021 13:09:46 -0500 Subject: add more debug stuff --- src/database.ts | 16 +++++++++++----- src/index.ts | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/database.ts b/src/database.ts index 37605a6..66d4142 100644 --- a/src/database.ts +++ b/src/database.ts @@ -233,6 +233,7 @@ async function getApplicableAttributes(member): Promise { /** Update the member's leaderboard data on the server if applicable */ export async function updateDatabaseMember(member: CleanMember, profile: CleanFullProfile): Promise { + if (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 if (recentlyUpdated.get(profile.uuid + member.uuid)) @@ -247,8 +248,12 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu await constants.addSkills(member.skills.map(skill => skill.name)) await constants.addZones(member.visited_zones.map(zone => zone.name)) + if (debug) console.log('done constants..') + const leaderboardAttributes = await getApplicableAttributes(member) + if (debug) console.log('done getApplicableAttributes..', leaderboardAttributes) + await memberLeaderboardsCollection.updateOne( { uuid: member.uuid, @@ -322,13 +327,14 @@ async function removeBadMemberLeaderboardAttributes(): Promise { } /** Fetch all the leaderboards, used for caching. Don't call this often! */ -async function fetchAllLeaderboards(): Promise { +async function fetchAllLeaderboards(fast?: boolean): Promise { const leaderboards = await fetchAllMemberLeaderboardAttributes() // shuffle so if the application is restarting many times itll still be useful if (debug) console.log('Caching leaderboards!') for (const leaderboard of shuffle(leaderboards)) { - // wait 2 seconds so it doesnt use as much ram - await sleep(2 * 1000) + if (!fast) + // wait 2 seconds so it doesnt use as much ram + await sleep(2 * 1000) await fetchMemberLeaderboard(leaderboard) } @@ -340,7 +346,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/src/index.ts b/src/index.ts index 4cf8dae..0d66c55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import rateLimit from 'express-rate-limit' const app = express() -export const debug = false +export const debug = true // 500 requests over 5 minutes const limiter = rateLimit({ -- cgit