cache statistics
This commit is contained in:
parent
c58f24103f
commit
b83fb6f3a8
@ -4,24 +4,35 @@ import { ScoreSaberScoreModel } from "@ssr/common/model/score/impl/scoresaber-sc
|
||||
import { AdditionalScoreDataModel } from "@ssr/common/model/additional-score-data/additional-score-data";
|
||||
import { BeatSaverMapModel } from "@ssr/common/model/beatsaver/map";
|
||||
import { ScoreSaberLeaderboardModel } from "@ssr/common/model/leaderboard/impl/scoresaber-leaderboard";
|
||||
import { SSRCache } from "@ssr/common/cache";
|
||||
|
||||
const statisticsCache = new SSRCache({
|
||||
ttl: 120 * 1000, // 2 minutes
|
||||
});
|
||||
|
||||
export class AppService {
|
||||
/**
|
||||
* Gets the app statistics.
|
||||
*/
|
||||
public static async getAppStatistics(): Promise<AppStatistics> {
|
||||
if (statisticsCache.has("app-statistics")) {
|
||||
return statisticsCache.get<AppStatistics>("app-statistics")!;
|
||||
}
|
||||
|
||||
const trackedPlayers = await PlayerModel.countDocuments();
|
||||
const trackedScores = await ScoreSaberScoreModel.countDocuments();
|
||||
const additionalScoresData = await AdditionalScoreDataModel.countDocuments();
|
||||
const cachedBeatSaverMaps = await BeatSaverMapModel.countDocuments();
|
||||
const cachedScoreSaberLeaderboards = await ScoreSaberLeaderboardModel.countDocuments();
|
||||
|
||||
return {
|
||||
const response = {
|
||||
trackedPlayers,
|
||||
trackedScores,
|
||||
additionalScoresData,
|
||||
cachedBeatSaverMaps,
|
||||
cachedScoreSaberLeaderboards,
|
||||
};
|
||||
statisticsCache.set("app-statistics", response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
type CacheOptions = {
|
||||
/**
|
||||
* The time the cached object will be valid for
|
||||
* The time (in ms) the cached object will be valid for
|
||||
*/
|
||||
ttl?: number;
|
||||
|
||||
|
Reference in New Issue
Block a user