Cache the heavy statistics lookup queries.
This commit is contained in:
parent
0fad0fbb42
commit
85f1d4d7aa
@ -253,11 +253,11 @@ class MempoolSpace {
|
|||||||
.get(config.API_ENDPOINT + 'fees/recommended', routes.getRecommendedFees)
|
.get(config.API_ENDPOINT + 'fees/recommended', routes.getRecommendedFees)
|
||||||
.get(config.API_ENDPOINT + 'fees/projected-blocks', routes.getProjectedBlocks)
|
.get(config.API_ENDPOINT + 'fees/projected-blocks', routes.getProjectedBlocks)
|
||||||
.get(config.API_ENDPOINT + 'statistics/2h', routes.get2HStatistics)
|
.get(config.API_ENDPOINT + 'statistics/2h', routes.get2HStatistics)
|
||||||
.get(config.API_ENDPOINT + 'statistics/24h', routes.get24HStatistics)
|
.get(config.API_ENDPOINT + 'statistics/24h', routes.get24HStatistics.bind(routes))
|
||||||
.get(config.API_ENDPOINT + 'statistics/1w', routes.get1WHStatistics)
|
.get(config.API_ENDPOINT + 'statistics/1w', routes.get1WHStatistics.bind(routes))
|
||||||
.get(config.API_ENDPOINT + 'statistics/1m', routes.get1MStatistics)
|
.get(config.API_ENDPOINT + 'statistics/1m', routes.get1MStatistics.bind(routes))
|
||||||
.get(config.API_ENDPOINT + 'statistics/3m', routes.get3MStatistics)
|
.get(config.API_ENDPOINT + 'statistics/3m', routes.get3MStatistics.bind(routes))
|
||||||
.get(config.API_ENDPOINT + 'statistics/6m', routes.get6MStatistics)
|
.get(config.API_ENDPOINT + 'statistics/6m', routes.get6MStatistics.bind(routes))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,36 +3,45 @@ import feeApi from './api/fee-api';
|
|||||||
import projectedBlocks from './api/projected-blocks';
|
import projectedBlocks from './api/projected-blocks';
|
||||||
|
|
||||||
class Routes {
|
class Routes {
|
||||||
constructor() {}
|
private cache = {};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.createCache();
|
||||||
|
setTimeout(this.createCache.bind(this), 600000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async createCache() {
|
||||||
|
this.cache['24h'] = await statistics.$list24H();
|
||||||
|
this.cache['1w'] = await statistics.$list1W();
|
||||||
|
this.cache['1m'] = await statistics.$list1M();
|
||||||
|
this.cache['3m'] = await statistics.$list3M();
|
||||||
|
this.cache['6m'] = await statistics.$list6M();
|
||||||
|
console.log('Statistics cache created');
|
||||||
|
}
|
||||||
|
|
||||||
public async get2HStatistics(req, res) {
|
public async get2HStatistics(req, res) {
|
||||||
const result = await statistics.$list2H();
|
const result = await statistics.$list2H();
|
||||||
res.send(result);
|
res.send(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get24HStatistics(req, res) {
|
public get24HStatistics(req, res) {
|
||||||
const result = await statistics.$list24H();
|
res.send(this.cache['24h']);
|
||||||
res.send(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get1WHStatistics(req, res) {
|
public get1WHStatistics(req, res) {
|
||||||
const result = await statistics.$list1W();
|
res.send(this.cache['1w']);
|
||||||
res.send(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get1MStatistics(req, res) {
|
public get1MStatistics(req, res) {
|
||||||
const result = await statistics.$list1M();
|
res.send(this.cache['1m']);
|
||||||
res.send(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get3MStatistics(req, res) {
|
public get3MStatistics(req, res) {
|
||||||
const result = await statistics.$list3M();
|
res.send(this.cache['3m']);
|
||||||
res.send(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get6MStatistics(req, res) {
|
public get6MStatistics(req, res) {
|
||||||
const result = await statistics.$list6M();
|
res.send(this.cache['6m']);
|
||||||
res.send(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getRecommendedFees(req, res) {
|
public async getRecommendedFees(req, res) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user