aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/hypixelCached.js16
-rw-r--r--src/cleaners/skyblock/collections.ts2
-rw-r--r--src/hypixelCached.ts12
3 files changed, 27 insertions, 3 deletions
diff --git a/build/hypixelCached.js b/build/hypixelCached.js
index 15a1cec..4af0816 100644
--- a/build/hypixelCached.js
+++ b/build/hypixelCached.js
@@ -30,6 +30,8 @@ const node_cache_1 = __importDefault(require("node-cache"));
const mojang = __importStar(require("./mojang"));
const hypixel = __importStar(require("./hypixel"));
const util_1 = require("./util");
+// TODO: put this somewhere else
+const debug = false;
// cache usernames for 4 hours
const usernameCache = new node_cache_1.default({
stdTTL: 60 * 60 * 4,
@@ -49,7 +51,7 @@ const playerCache = new node_cache_1.default({
const profileCache = new node_cache_1.default({
stdTTL: 30,
checkperiod: 10,
- useClones: false,
+ useClones: true,
});
const profilesCache = new node_cache_1.default({
stdTTL: 60 * 3,
@@ -91,6 +93,8 @@ exports.uuidFromUser = uuidFromUser;
*/
async function usernameFromUser(user) {
if (usernameCache.has(util_1.undashUuid(user))) {
+ if (debug)
+ console.log('Cache hit! usernameFromUser', user);
return usernameCache.get(util_1.undashUuid(user));
}
let { uuid, username } = await mojang.mojangDataFromUser(user);
@@ -102,6 +106,8 @@ exports.usernameFromUser = usernameFromUser;
async function fetchPlayer(user) {
const playerUuid = await uuidFromUser(user);
if (playerCache.has(playerUuid)) {
+ if (debug)
+ console.log('Cache hit! fetchPlayer', playerUuid);
return playerCache.get(playerUuid);
}
const cleanPlayer = await hypixel.sendCleanApiRequest({
@@ -117,6 +123,8 @@ async function fetchPlayer(user) {
exports.fetchPlayer = fetchPlayer;
async function fetchSkyblockProfiles(playerUuid) {
if (profilesCache.has(playerUuid)) {
+ if (debug)
+ console.log('Cache hit! fetchSkyblockProfiles', playerUuid);
return profilesCache.get(playerUuid);
}
const profiles = await hypixel.sendCleanApiRequest({
@@ -155,6 +163,8 @@ exports.fetchSkyblockProfiles = fetchSkyblockProfiles;
async function fetchBasicProfiles(user) {
const playerUuid = await uuidFromUser(user);
if (basicProfilesCache.has(playerUuid)) {
+ if (debug)
+ console.log('Cache hit! fetchBasicProfiles', playerUuid);
return basicProfilesCache.get(playerUuid);
}
const player = await fetchPlayer(playerUuid);
@@ -194,6 +204,8 @@ async function fetchProfile(user, profile) {
const profileUuid = await fetchProfileUuid(playerUuid, profile);
if (profileCache.has(profileUuid)) {
// we have the profile cached, return it :)
+ if (debug)
+ console.log('Cache hit! fetchProfile', profileUuid);
return profileCache.get(profileUuid);
}
const profileName = await fetchProfileName(user, profile);
@@ -218,6 +230,8 @@ async function fetchProfileName(user, profile) {
const playerUuid = await uuidFromUser(user);
if (profileNameCache.has(`${playerUuid}.${profileUuid}`)) {
// Return the profile name if it's cached
+ if (debug)
+ console.log('Cache hit! fetchProfileName', profileUuid);
return profileNameCache.get(`${playerUuid}.${profileUuid}`);
}
const basicProfiles = await fetchBasicProfiles(playerUuid);
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts
index 3b1a178..a3e1fb3 100644
--- a/src/cleaners/skyblock/collections.ts
+++ b/src/cleaners/skyblock/collections.ts
@@ -1,4 +1,4 @@
-import { cleanItemId, cleanItemNames, hypixelItemNames } from "./itemId"
+import { cleanItemId, hypixelItemNames } from "./itemId"
const COLLECTIONS = {
'farming': [
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index ae544a2..e311fe6 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -10,6 +10,10 @@ import { undashUuid } from './util'
import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile'
+// TODO: put this somewhere else
+const debug = false
+
+
// cache usernames for 4 hours
const usernameCache = new NodeCache({
stdTTL: 60 * 60 * 4,
@@ -32,7 +36,7 @@ const playerCache = new NodeCache({
const profileCache = new NodeCache({
stdTTL: 30,
checkperiod: 10,
- useClones: false,
+ useClones: true,
})
const profilesCache = new NodeCache({
@@ -79,6 +83,7 @@ export async function uuidFromUser(user: string): Promise<string> {
*/
export async function usernameFromUser(user: string): Promise<string> {
if (usernameCache.has(undashUuid(user))) {
+ if (debug) console.log('Cache hit! usernameFromUser', user)
return usernameCache.get(undashUuid(user))
}
@@ -93,6 +98,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer> {
const playerUuid = await uuidFromUser(user)
if (playerCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchPlayer', playerUuid)
return playerCache.get(playerUuid)
}
@@ -112,6 +118,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer> {
export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanProfile[]> {
if (profilesCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchSkyblockProfiles', playerUuid)
return profilesCache.get(playerUuid)
}
@@ -157,6 +164,7 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
async function fetchBasicProfiles(user: string): Promise<CleanBasicProfile[]> {
const playerUuid = await uuidFromUser(user)
if (basicProfilesCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchBasicProfiles', playerUuid)
return basicProfilesCache.get(playerUuid)
}
const player = await fetchPlayer(playerUuid)
@@ -202,6 +210,7 @@ export async function fetchProfile(user: string, profile: string): Promise<Clean
if (profileCache.has(profileUuid)) {
// we have the profile cached, return it :)
+ if (debug) console.log('Cache hit! fetchProfile', profileUuid)
return profileCache.get(profileUuid)
}
@@ -236,6 +245,7 @@ export async function fetchProfileName(user: string, profile: string): Promise<s
if (profileNameCache.has(`${playerUuid}.${profileUuid}`)) {
// Return the profile name if it's cached
+ if (debug) console.log('Cache hit! fetchProfileName', profileUuid)
return profileNameCache.get(`${playerUuid}.${profileUuid}`)
}