meow
This commit is contained in:
parent
da7f5f1c62
commit
6bc2e09f43
@ -40,13 +40,17 @@ export default class LeaderboardService {
|
|||||||
let leaderboard: Leaderboard | undefined;
|
let leaderboard: Leaderboard | undefined;
|
||||||
let beatSaverMap: BeatSaverMap | undefined;
|
let beatSaverMap: BeatSaverMap | undefined;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
switch (leaderboardName) {
|
switch (leaderboardName) {
|
||||||
case "scoresaber": {
|
case "scoresaber": {
|
||||||
let foundLeaderboard = false;
|
let foundLeaderboard = false;
|
||||||
const cachedLeaderboard = await ScoreSaberLeaderboardModel.findById(id);
|
const cachedLeaderboard = await ScoreSaberLeaderboardModel.findById(id);
|
||||||
if (cachedLeaderboard != null) {
|
if (cachedLeaderboard != null) {
|
||||||
leaderboard = cachedLeaderboard as unknown as ScoreSaberLeaderboard;
|
leaderboard = cachedLeaderboard as unknown as ScoreSaberLeaderboard;
|
||||||
if (!leaderboard.shouldRefresh()) {
|
if (
|
||||||
|
leaderboard.lastRefreshed == undefined ||
|
||||||
|
now.getTime() - leaderboard.lastRefreshed.getTime() > 1000 * 60 * 60 * 24
|
||||||
|
) {
|
||||||
foundLeaderboard = true;
|
foundLeaderboard = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ export default class Leaderboard {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
private readonly _id!: number;
|
private readonly _id?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hash of the song this leaderboard is for.
|
* The hash of the song this leaderboard is for.
|
||||||
@ -93,20 +93,7 @@ export default class Leaderboard {
|
|||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
lastRefreshed?: Date;
|
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 {
|
get id(): number {
|
||||||
return this._id;
|
return this._id ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user