Removing statistics cache and setting headers

This commit is contained in:
softsimon
2022-01-12 20:57:25 +04:00
parent 337f40a470
commit ee4c9f5727
3 changed files with 54 additions and 67 deletions

View File

@@ -10,9 +10,6 @@ class Statistics {
protected intervalTimer: NodeJS.Timer | undefined;
protected newStatisticsEntryCallback: ((stats: OptimizedStatistic) => void) | undefined;
protected queryTimeout = 120000;
protected cache: { [date: string]: OptimizedStatistic[] } = {
'24h': [], '1w': [], '1m': [], '3m': [], '6m': [], '1y': [], '2y': [], '3y': []
};
public setNewStatisticsEntryCallback(fn: (stats: OptimizedStatistic) => void) {
this.newStatisticsEntryCallback = fn;
@@ -34,25 +31,6 @@ class Statistics {
this.runStatistics();
}, 1 * 60 * 1000);
}, difference);
this.createCache();
setInterval(this.createCache.bind(this), 600000);
}
public getCache() {
return this.cache;
}
private async createCache() {
this.cache['24h'] = await this.$list24H();
this.cache['1w'] = await this.$list1W();
this.cache['1m'] = await this.$list1M();
this.cache['3m'] = await this.$list3M();
this.cache['6m'] = await this.$list6M();
this.cache['1y'] = await this.$list1Y();
this.cache['2y'] = await this.$list2Y();
this.cache['3y'] = await this.$list3Y();
logger.debug('Statistics cache created');
}
private async runStatistics(): Promise<void> {
@@ -365,7 +343,7 @@ class Statistics {
ORDER BY added DESC;`;
}
public async $get(id: number): Promise<OptimizedStatistic | undefined> {
private async $get(id: number): Promise<OptimizedStatistic | undefined> {
try {
const connection = await DB.pool.getConnection();
const query = `SELECT *, UNIX_TIMESTAMP(added) as added FROM statistics WHERE id = ?`;