aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-04-08 13:09:46 -0500
committermat <27899617+mat-1@users.noreply.github.com>2021-04-08 13:09:46 -0500
commitddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d (patch)
tree19be2de22ba134db9b46c7eb370fc0a5106af9fb /src
parentcbfcd38f22871a9b1520a66014288df62afb61fe (diff)
downloadskyblock-api-ddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d.tar.gz
skyblock-api-ddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d.tar.bz2
skyblock-api-ddf9d089eea7e1f48f2a7b255d02e3efc2db0f3d.zip
add more debug stuff
Diffstat (limited to 'src')
-rw-r--r--src/database.ts16
-rw-r--r--src/index.ts2
2 files changed, 12 insertions, 6 deletions
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<StringNumber> {
/** Update the member's leaderboard data on the server if applicable */
export async function updateDatabaseMember(member: CleanMember, profile: CleanFullProfile): Promise<void> {
+ 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<void> {
}
/** Fetch all the leaderboards, used for caching. Don't call this often! */
-async function fetchAllLeaderboards(): Promise<void> {
+async function fetchAllLeaderboards(fast?: boolean): Promise<void> {
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({