diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-14 20:27:42 -0500 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-14 20:27:42 -0500 |
commit | 52907cf2056cd434dad7270475fc9e4a532c04fa (patch) | |
tree | ed4f185f5d9c36161c3b759c8616a2c7818c58dc | |
parent | 0e5887326f1ba1f8005ca0bd217c5b332a1fb6cf (diff) | |
download | skyblock-api-52907cf2056cd434dad7270475fc9e4a532c04fa.tar.gz skyblock-api-52907cf2056cd434dad7270475fc9e4a532c04fa.tar.bz2 skyblock-api-52907cf2056cd434dad7270475fc9e4a532c04fa.zip |
Revert "Total leaderboards leaderboard (#5)"
This reverts commit 0e5887326f1ba1f8005ca0bd217c5b332a1fb6cf.
-rw-r--r-- | build/database.js | 14 | ||||
-rw-r--r-- | build/hypixelApi.js | 1 | ||||
-rw-r--r-- | build/hypixelCached.js | 10 | ||||
-rw-r--r-- | src/database.ts | 20 | ||||
-rw-r--r-- | src/hypixelApi.ts | 2 | ||||
-rw-r--r-- | src/hypixelCached.ts | 14 |
6 files changed, 8 insertions, 53 deletions
diff --git a/build/database.js b/build/database.js index 2c57d8c..e889f1e 100644 --- a/build/database.js +++ b/build/database.js @@ -155,7 +155,6 @@ async function fetchAllMemberLeaderboardAttributes() { 'first_join', 'purse', 'visited_zones', - 'leaderboards_count' ]; } exports.fetchAllMemberLeaderboardAttributes = fetchAllMemberLeaderboardAttributes; @@ -215,7 +214,7 @@ async function fetchMemberLeaderboardSpots(player, profile) { const fullMember = fullProfile.members.find(m => m.username.toLowerCase() === player.toLowerCase() || m.uuid === player); // update the leaderboard positions for the member await updateDatabaseMember(fullMember, fullProfile); - const applicableAttributes = await getApplicableAttributes(fullMember, fullProfile); + const applicableAttributes = await getApplicableAttributes(fullMember); const memberLeaderboardSpots = []; for (const leaderboardName in applicableAttributes) { const leaderboard = await fetchMemberLeaderboardRaw(leaderboardName); @@ -239,7 +238,7 @@ async function getMemberLeaderboardRequirement(name) { return null; } /** Get the attributes for the member, but only ones that would put them on the top 100 for leaderboards */ -async function getApplicableAttributes(member, profile) { +async function getApplicableAttributes(member) { const leaderboardAttributes = getMemberLeaderboardAttributes(member); const applicableAttributes = {}; for (const [leaderboard, attributeValue] of Object.entries(leaderboardAttributes)) { @@ -250,13 +249,6 @@ async function getApplicableAttributes(member, profile) { applicableAttributes[leaderboard] = attributeValue; } } - let leaderboardsCount = Object.keys(applicableAttributes).length; - const leaderboardsCountRequirement = await getMemberLeaderboardRequirement('leaderboards_count'); - if ((leaderboardsCountRequirement === null) - || (leaderboardsCount > leaderboardsCountRequirement)) { - // add 1 extra because this attribute also counts :) - applicableAttributes['leaderboards_count'] = leaderboardsCount + 1; - } return applicableAttributes; } /** Update the member's leaderboard data on the server if applicable */ @@ -279,7 +271,7 @@ async function updateDatabaseMember(member, profile) { await constants.addSlayers(member.slayers.bosses.map(s => s.raw_name)); if (_1.debug) console.log('done constants..'); - const leaderboardAttributes = await getApplicableAttributes(member, profile); + const leaderboardAttributes = await getApplicableAttributes(member); if (_1.debug) console.log('done getApplicableAttributes..', leaderboardAttributes); await memberLeaderboardsCollection.updateOne({ diff --git a/build/hypixelApi.js b/build/hypixelApi.js index c40fe0f..2b3a601 100644 --- a/build/hypixelApi.js +++ b/build/hypixelApi.js @@ -56,7 +56,6 @@ async function sendApiRequest({ path, key, args }) { fetchResponse = await node_fetch_1.default(fetchUrl, { agent: () => httpsAgent }); } catch { - console.log('error in fetch :/'); // if there's an error, wait a second and try again await new Promise((resolve) => setTimeout(resolve, 1000)); return await sendApiRequest({ path, key, args }); diff --git a/build/hypixelCached.js b/build/hypixelCached.js index 8a35482..a667ec4 100644 --- a/build/hypixelCached.js +++ b/build/hypixelCached.js @@ -145,24 +145,14 @@ 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 diff --git a/src/database.ts b/src/database.ts index 27bc7ec..08a8114 100644 --- a/src/database.ts +++ b/src/database.ts @@ -3,7 +3,7 @@ */ import { categorizeStat, getStatUnit } from './cleaners/skyblock/stats' -import { CleanFullProfile, CleanProfile } from './cleaners/skyblock/profile' +import { CleanFullProfile } from './cleaners/skyblock/profile' import { CleanMember } from './cleaners/skyblock/member' import { Collection, Db, MongoClient } from 'mongodb' import { CleanPlayer } from './cleaners/player' @@ -175,7 +175,6 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { 'first_join', 'purse', 'visited_zones', - 'leaderboards_count' ] } @@ -248,7 +247,7 @@ export async function fetchMemberLeaderboardSpots(player: string, profile: strin // update the leaderboard positions for the member await updateDatabaseMember(fullMember, fullProfile) - const applicableAttributes = await getApplicableAttributes(fullMember, fullProfile) + const applicableAttributes = await getApplicableAttributes(fullMember) const memberLeaderboardSpots = [] @@ -277,7 +276,7 @@ async function getMemberLeaderboardRequirement(name: string): Promise<number> { } /** Get the attributes for the member, but only ones that would put them on the top 100 for leaderboards */ -async function getApplicableAttributes(member: CleanMember, profile: CleanProfile): Promise<StringNumber> { +async function getApplicableAttributes(member: CleanMember): Promise<StringNumber> { const leaderboardAttributes = getMemberLeaderboardAttributes(member) const applicableAttributes = {} for (const [ leaderboard, attributeValue ] of Object.entries(leaderboardAttributes)) { @@ -290,17 +289,6 @@ async function getApplicableAttributes(member: CleanMember, profile: CleanProfil applicableAttributes[leaderboard] = attributeValue } } - - let leaderboardsCount: number = Object.keys(applicableAttributes).length - const leaderboardsCountRequirement: number = await getMemberLeaderboardRequirement('leaderboards_count') - if ( - (leaderboardsCountRequirement === null) - || (leaderboardsCount > leaderboardsCountRequirement) - ) { - // add 1 extra because this attribute also counts :) - applicableAttributes['leaderboards_count'] = leaderboardsCount + 1 - } - return applicableAttributes } @@ -324,7 +312,7 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu if (debug) console.log('done constants..') - const leaderboardAttributes = await getApplicableAttributes(member, profile) + const leaderboardAttributes = await getApplicableAttributes(member) if (debug) console.log('done getApplicableAttributes..', leaderboardAttributes) diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index 7ee7eca..8541089 100644 --- a/src/hypixelApi.ts +++ b/src/hypixelApi.ts @@ -125,6 +125,7 @@ export interface HypixelPlayer { socialMedia?: HypixelPlayerSocialMedia } + /** Send an HTTP request to the Hypixel API */ export async function sendApiRequest({ path, key, args }): Promise<HypixelResponse> { // Send a raw http request to api.hypixel.net, and return the parsed json @@ -144,7 +145,6 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon { agent: () => httpsAgent } ) } catch { - console.log('error in fetch :/') // if there's an error, wait a second and try again await new Promise((resolve) => setTimeout(resolve, 1000)) return await sendApiRequest({ path, key, args }) diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index 3dc89a3..c347a1a 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -143,32 +143,18 @@ export async function usernameFromUser(user: string): Promise<string> { return username } -let fetchingPlayers: Set<string> = new Set() export async function fetchPlayer(user: string): Promise<CleanPlayer> { 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: CleanPlayer = await hypixel.sendCleanApiRequest({ path: 'player', args: { uuid: playerUuid } }) - fetchingPlayers.delete(playerUuid) - if (!cleanPlayer) return // clone in case it gets modified somehow later |