Optimize price API response size reduce the number of query to that API

This commit is contained in:
nymkappa
2023-02-23 13:13:20 +09:00
parent f6c7839524
commit 5749820999
6 changed files with 132 additions and 50 deletions

View File

@@ -41,7 +41,13 @@ class MiningRoutes {
res.header('Pragma', 'public');
res.header('Cache-control', 'public');
res.setHeader('Expires', new Date(Date.now() + 1000 * 300).toUTCString());
res.status(200).send(await PricesRepository.$getHistoricalPrice());
if (req.query.timestamp) {
res.status(200).send(await PricesRepository.$getNearestHistoricalPrice(
parseInt(<string>req.query.timestamp ?? 0, 10)
));
} else {
res.status(200).send(await PricesRepository.$getHistoricalPrices());
}
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}