From c31e4fe77467486dc03226ebdad4c0bc67e1d715 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Wed, 14 Apr 2021 21:24:11 -0500 Subject: Total leaderboards leaderboard working (#6) * add leaderboards leaderboard * slightly optimize fetchPlayer to not unnecessarily fetch the same player twice * Compiled TS into JS * fix errors with fetch * fix random bugs that made people disappear from leaderboards --- build/hypixelCached.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'build/hypixelCached.js') diff --git a/build/hypixelCached.js b/build/hypixelCached.js index a667ec4..8a35482 100644 --- a/build/hypixelCached.js +++ b/build/hypixelCached.js @@ -145,14 +145,24 @@ async function usernameFromUser(user) { return username; } exports.usernameFromUser = usernameFromUser; +let fetchingPlayers = new Set(); async function fetchPlayer(user) { const playerUuid = await uuidFromUser(user); if (playerCache.has(playerUuid)) return playerCache.get(playerUuid); + // if it's already in the process of fetching, check every 100ms until it's not fetching the player anymore and fetch it again, since it'll be cached now + if (fetchingPlayers.has(playerUuid)) { + while (fetchingPlayers.has(playerUuid)) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return await fetchPlayer(user); + } + fetchingPlayers.add(playerUuid); const cleanPlayer = await hypixel.sendCleanApiRequest({ path: 'player', args: { uuid: playerUuid } }); + fetchingPlayers.delete(playerUuid); if (!cleanPlayer) return; // clone in case it gets modified somehow later -- cgit