meow
All checks were successful
Deploy Backend / docker (ubuntu-latest) (push) Successful in 45s
Deploy Website / docker (ubuntu-latest) (push) Successful in 2m25s

This commit is contained in:
Lee 2024-10-26 13:16:55 +01:00
parent da7f5f1c62
commit 6bc2e09f43
2 changed files with 7 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}