Skip to content

Commit

Permalink
ensure the list of scores exists
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Jan 25, 2024
1 parent a1c98da commit e454b20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 9 additions & 7 deletions server/api/richList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ const getRichListPage = async (page = 1) =>
"WITHSCORES",
(err, list) => {
const data = [];
list.forEach(value => {
if (value.startsWith("nano_")) {
data.push({ account: value });
} else {
data[data.length - 1].balance = parseFloat(value);
}
});
list &&
list.length &&
list.forEach(value => {
if (value.startsWith("nano_")) {
data.push({ account: value });
} else {
data[data.length - 1].balance = parseFloat(value);
}
});

if (err) Sentry.captureException(err);
resolve({ data, meta: { total, perPage: PER_PAGE, offset } });
Expand Down
10 changes: 6 additions & 4 deletions server/cron/coingeckoStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const getPriceStats = async fiats => {
bitcoin: json.bitcoin,
nano: json.nano,
});

await sleep(25_000);
}
} catch (err) {
console.log("Error", err);
Expand Down Expand Up @@ -88,7 +90,7 @@ const getMarketStats = async fiats => {

nodeCache.set(`${COINGECKO_MARKET_STATS}-${fiat}`, marketStats);

await sleep(20000);
await sleep(20_000);
}
} catch (err) {
// rate limited
Expand Down Expand Up @@ -213,9 +215,9 @@ const getMarketCapStats = async () => {

// CoinGecko rate limit is 10 calls per seconds
if (i && !(i % 10)) {
await sleep(25000);
await sleep(25_000);
} else {
await sleep(process.env.NODE_ENV === "production" ? 15000 : 150);
await sleep(process.env.NODE_ENV === "production" ? 15_000 : 150);
}
}

Expand All @@ -225,7 +227,7 @@ const getMarketCapStats = async () => {
});
} else {
console.log(`Failed to get top ${top} cryptocurrencies`, cryptocurrencies);
await sleep(10000);
await sleep(10_000);

getMarketCapStats();
return;
Expand Down

0 comments on commit e454b20

Please sign in to comment.