From 6bc2e09f43cb4b8c42e4605ea0274d71ad951466 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 26 Oct 2024 13:16:55 +0100 Subject: [PATCH] meow --- .../backend/src/service/leaderboard.service.ts | 6 +++++- .../common/src/model/leaderboard/leaderboard.ts | 17 ++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/projects/backend/src/service/leaderboard.service.ts b/projects/backend/src/service/leaderboard.service.ts index 9456fac..eaf923a 100644 --- a/projects/backend/src/service/leaderboard.service.ts +++ b/projects/backend/src/service/leaderboard.service.ts @@ -40,13 +40,17 @@ export default class LeaderboardService { let leaderboard: Leaderboard | undefined; let beatSaverMap: BeatSaverMap | undefined; + const now = new Date(); switch (leaderboardName) { case "scoresaber": { let foundLeaderboard = false; const cachedLeaderboard = await ScoreSaberLeaderboardModel.findById(id); if (cachedLeaderboard != null) { leaderboard = cachedLeaderboard as unknown as ScoreSaberLeaderboard; - if (!leaderboard.shouldRefresh()) { + if ( + leaderboard.lastRefreshed == undefined || + now.getTime() - leaderboard.lastRefreshed.getTime() > 1000 * 60 * 60 * 24 + ) { foundLeaderboard = true; } } diff --git a/projects/common/src/model/leaderboard/leaderboard.ts b/projects/common/src/model/leaderboard/leaderboard.ts index 33d9087..4b443ef 100644 --- a/projects/common/src/model/leaderboard/leaderboard.ts +++ b/projects/common/src/model/leaderboard/leaderboard.ts @@ -7,7 +7,7 @@ export default class Leaderboard { * @private */ @Prop({ required: true }) - private readonly _id!: number; + private readonly _id?: number; /** * The hash of the song this leaderboard is for. @@ -93,20 +93,7 @@ export default class Leaderboard { @Prop({ required: true }) lastRefreshed?: Date; - /** - * Should the map data be refreshed? - * - * @returns true if the map data should be refreshed - */ - public shouldRefresh(): boolean { - if (!this.lastRefreshed) { - return true; - } - const now = new Date(); - return now.getTime() - this.lastRefreshed.getTime() > 1000 * 60 * 60 * 24; // 1 day - } - get id(): number { - return this._id; + return this._id ?? 0; } }