aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-05-27 20:29:30 -0500
committermat <github@matdoes.dev>2021-05-27 20:29:30 -0500
commitf2f18c27d2e849fdc3b2a6766dc6ab4005cde7df (patch)
tree641ea6ec80309cbbccd70834b47d0c6fa769cf99
parentf065fd2dd0fa38870727069e0ff2382c21cfe080 (diff)
downloadskyblock-api-f2f18c27d2e849fdc3b2a6766dc6ab4005cde7df.tar.gz
skyblock-api-f2f18c27d2e849fdc3b2a6766dc6ab4005cde7df.tar.bz2
skyblock-api-f2f18c27d2e849fdc3b2a6766dc6ab4005cde7df.zip
random random debug things and optimize leaderboards
optimize leaderboards by fetching all the raw ones at the beginning
-rw-r--r--build/database.js4
-rw-r--r--build/discord.js1
-rw-r--r--build/hypixelApi.js1
-rw-r--r--build/index.js2
-rw-r--r--src/database.ts6
-rw-r--r--src/discord.ts1
-rw-r--r--src/hypixelApi.ts1
-rw-r--r--src/index.ts2
8 files changed, 10 insertions, 8 deletions
diff --git a/build/database.js b/build/database.js
index 55c86eb..07ed52e 100644
--- a/build/database.js
+++ b/build/database.js
@@ -506,8 +506,10 @@ async function fetchAllLeaderboards(fast) {
const leaderboards = await fetchAllMemberLeaderboardAttributes();
if (_1.debug)
console.debug('Caching raw leaderboards!');
+ const promises = [];
for (const leaderboard of util_1.shuffle(leaderboards))
- await fetchMemberLeaderboardRaw(leaderboard);
+ promises.push(fetchMemberLeaderboardRaw(leaderboard));
+ await Promise.all(promises);
// shuffle so if the application is restarting many times itll still be useful
if (_1.debug)
console.debug('Caching leaderboards!');
diff --git a/build/discord.js b/build/discord.js
index be085bb..a92521a 100644
--- a/build/discord.js
+++ b/build/discord.js
@@ -21,7 +21,6 @@ async function exchangeCode(redirectUri, code) {
'redirect_uri': redirectUri,
'scope': 'identify'
};
- console.log(new URLSearchParams(data).toString());
const fetchResponse = await node_fetch_1.default(API_ENDPOINT + '/oauth2/token', {
method: 'POST',
agent: () => httpsAgent,
diff --git a/build/hypixelApi.js b/build/hypixelApi.js
index 15c8817..9f54ef2 100644
--- a/build/hypixelApi.js
+++ b/build/hypixelApi.js
@@ -55,7 +55,6 @@ async function sendApiRequest({ path, key, args }) {
let fetchResponse;
let fetchJsonParsed;
try {
- console.log(fetchUrl);
fetchResponse = await node_fetch_1.default(fetchUrl, { agent: () => httpsAgent });
fetchJsonParsed = await fetchResponse.json();
}
diff --git a/build/index.js b/build/index.js
index 0f0b570..fb2789d 100644
--- a/build/index.js
+++ b/build/index.js
@@ -30,7 +30,7 @@ const constants = __importStar(require("./constants"));
const discord = __importStar(require("./discord"));
const express_1 = __importDefault(require("express"));
const app = express_1.default();
-exports.debug = false;
+exports.debug = true;
const mainSiteUrl = 'https://skyblock.matdoes.dev';
// 200 requests over 5 minutes
const limiter = express_rate_limit_1.default({
diff --git a/src/database.ts b/src/database.ts
index 7129d2b..bb3bf3a 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -637,8 +637,12 @@ async function fetchAllLeaderboards(fast?: boolean): Promise<void> {
const leaderboards: string[] = await fetchAllMemberLeaderboardAttributes()
if (debug) console.debug('Caching raw leaderboards!')
+
+ const promises: Promise<DatabaseMemberLeaderboardItem[]>[] = []
+
for (const leaderboard of shuffle(leaderboards))
- await fetchMemberLeaderboardRaw(leaderboard)
+ promises.push(fetchMemberLeaderboardRaw(leaderboard))
+ await Promise.all(promises)
// shuffle so if the application is restarting many times itll still be useful
if (debug) console.debug('Caching leaderboards!')
diff --git a/src/discord.ts b/src/discord.ts
index 41f4c6e..48146b5 100644
--- a/src/discord.ts
+++ b/src/discord.ts
@@ -37,7 +37,6 @@ export async function exchangeCode(redirectUri: string, code: string): Promise<T
'redirect_uri': redirectUri,
'scope': 'identify'
}
- console.log(new URLSearchParams(data).toString())
const fetchResponse = await fetch(
API_ENDPOINT + '/oauth2/token',
{
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index 4807b2b..72af1af 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -140,7 +140,6 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon
let fetchJsonParsed: any
try {
- console.log(fetchUrl)
fetchResponse = await fetch(
fetchUrl,
{ agent: () => httpsAgent }
diff --git a/src/index.ts b/src/index.ts
index 0937e4e..176b73f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,7 +7,7 @@ import express from 'express'
const app = express()
-export const debug = false
+export const debug = true
const mainSiteUrl = 'https://skyblock.matdoes.dev'