Remove daily lb cache (#4231)

* Remove daily lb cache

* remove init

* lint
This commit is contained in:
Bruce Berrios 2023-04-30 11:25:18 -04:00 committed by GitHub
parent fa32e08c0e
commit 8ee934c69d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 4 additions and 41 deletions

View file

@ -1,7 +1,4 @@
import {
initializeDailyLeaderboardsCache,
getDailyLeaderboard,
} from "../../src/utils/daily-leaderboards";
import { getDailyLeaderboard } from "../../src/utils/daily-leaderboards";
const dailyLeaderboardsConfig = {
enabled: true,
@ -19,7 +16,6 @@ const dailyLeaderboardsConfig = {
mode2: "\\d+",
},
],
dailyLeaderboardCacheSize: 3,
topResultsToAnnounce: 3,
xpRewardBrackets: [],
scheduleRewardsModeRules: [],
@ -27,8 +23,6 @@ const dailyLeaderboardsConfig = {
describe("Daily Leaderboards", () => {
it("should properly handle valid and invalid modes", () => {
initializeDailyLeaderboardsCache(dailyLeaderboardsConfig);
const modeCases = [
{
case: {

View file

@ -79,8 +79,6 @@ export const BASE_CONFIGURATION: MonkeyTypes.Configuration = {
leaderboardExpirationTimeInDays: 0,
validModeRules: [],
scheduleRewardsModeRules: [],
// GOTCHA! MUST ATLEAST BE 1, LRUCache module will make process crash and die
dailyLeaderboardCacheSize: 1,
topResultsToAnnounce: 1, // This should never be 0. Setting to zero will announce all results.
xpRewardBrackets: [],
},
@ -453,11 +451,6 @@ export const CONFIGURATION_FORM_SCHEMA: ObjectSchema<MonkeyTypes.Configuration>
},
},
},
dailyLeaderboardCacheSize: {
type: "number",
label: "Daily Leaderboard Cache Size",
min: 1,
},
topResultsToAnnounce: {
type: "number",
label: "Top Results To Announce",

View file

@ -2,7 +2,6 @@ import "dotenv/config";
import * as db from "./init/db";
import jobs from "./jobs";
import { getLiveConfiguration } from "./init/configuration";
import { initializeDailyLeaderboardsCache } from "./utils/daily-leaderboards";
import app from "./app";
import { Server } from "http";
import { version } from "./version";
@ -26,7 +25,7 @@ async function bootServer(port: number): Promise<Server> {
initFirebaseAdmin();
Logger.info("Fetching live configuration...");
const liveConfiguration = await getLiveConfiguration();
await getLiveConfiguration();
Logger.success("Live configuration fetched");
Logger.info("Initializing email client...");
@ -60,8 +59,6 @@ async function bootServer(port: number): Promise<Server> {
);
}
initializeDailyLeaderboardsCache(liveConfiguration.dailyLeaderboards);
Logger.info("Starting cron jobs...");
jobs.forEach((job) => job.start());
Logger.success("Cron jobs started");

View file

@ -85,7 +85,6 @@ declare namespace MonkeyTypes {
maxResults: number;
validModeRules: ValidModeRule[];
scheduleRewardsModeRules: ValidModeRule[];
dailyLeaderboardCacheSize: number;
topResultsToAnnounce: number;
xpRewardBrackets: RewardBracket[];
};

View file

@ -1,5 +1,4 @@
import _ from "lodash";
import LRUCache from "lru-cache";
import * as RedisClient from "../init/redis";
import LaterQueue from "../queues/later-queue";
import { getCurrentDayTimestamp, matchesAPattern, kogascore } from "./misc";
@ -189,18 +188,6 @@ export async function purgeUserFromDailyLeaderboards(
await connection.purgeResults(0, uid, dailyLeaderboardNamespace);
}
let DAILY_LEADERBOARDS: LRUCache<string, DailyLeaderboard>;
export function initializeDailyLeaderboardsCache(
configuration: MonkeyTypes.Configuration["dailyLeaderboards"]
): void {
const { dailyLeaderboardCacheSize } = configuration;
DAILY_LEADERBOARDS = new LRUCache({
max: dailyLeaderboardCacheSize,
});
}
function isValidModeRule(
modeRule: MonkeyTypes.ValidModeRule,
modeRules: MonkeyTypes.ValidModeRule[]
@ -227,16 +214,9 @@ export function getDailyLeaderboard(
const modeRule = { language, mode, mode2 };
const isValidMode = isValidModeRule(modeRule, validModeRules);
if (!enabled || !isValidMode || !DAILY_LEADERBOARDS) {
if (!enabled || !isValidMode) {
return null;
}
const key = `${language}:${mode}:${mode2}:${customTimestamp}`;
if (!DAILY_LEADERBOARDS.has(key)) {
const dailyLeaderboard = new DailyLeaderboard(modeRule, customTimestamp);
DAILY_LEADERBOARDS.set(key, dailyLeaderboard);
}
return DAILY_LEADERBOARDS.get(key) ?? null;
return new DailyLeaderboard(modeRule, customTimestamp);
}