Skip to content

Commit

Permalink
update cache every three days
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Jul 25, 2024
1 parent ac9c9c4 commit f3a97fc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions projects/xrpl-dex/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ async function main() {
const projectKey = 'xrpl-dex'
const cacheKey = 'cache'
let { allPools, lastPoolUpdate, lastDataUpdate, tvl } = await getCache(projectKey, cacheKey)
if (!lastPoolUpdate || timeNow - lastPoolUpdate > aDayInSeconds) {
console.time("xrpl-dex fetch pool list");
allPools = await discoverPools(null, 1);
console.timeEnd("xrpl-dex fetch pool list");
lastPoolUpdate = getTimeNow();
await setCache(projectKey, cacheKey, { allPools, lastPoolUpdate, lastDataUpdate, tvl })
if (!lastPoolUpdate || timeNow - lastPoolUpdate > 3 * aDayInSeconds) {
try {
console.time("xrpl-dex fetch pool list");
allPools = await discoverPools(null, 1);
console.timeEnd("xrpl-dex fetch pool list");
lastPoolUpdate = getTimeNow();
await setCache(projectKey, cacheKey, { allPools, lastPoolUpdate, lastDataUpdate, tvl })
} catch (e) {
console.error(e)
}
}
if (lastDataUpdate && timeNow - lastDataUpdate < 2 * 60 * 60) {
// data was updated recently, no need to update
Expand All @@ -152,8 +156,10 @@ async function main() {
token1Bal: i.token1Reserve.amount,
})),
})
await setCache(projectKey, cacheKey, { allPools, lastPoolUpdate, lastDataUpdate: getTimeNow(), tvl: {
ripple: tvl.ripple,
'ripple:XRP': tvl['ripple:XRP'],
} })
await setCache(projectKey, cacheKey, {
allPools, lastPoolUpdate, lastDataUpdate: getTimeNow(), tvl: {
ripple: tvl.ripple,
'ripple:XRP': tvl['ripple:XRP'],
}
})
}

0 comments on commit f3a97fc

Please sign in to comment.