diff options
| author | Adam Soltys <[email protected]> | 2024-10-15 14:03:32 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-15 14:03:34 -0700 |
| commit | aa165827fdeba6bb4c0602f0a0168570d6379dd9 (patch) | |
| tree | dead5b12eadd0669aade5b945d8dd407cff9b4cc /lib | |
| parent | 842c29086c0dd06554f6809194c7a2e86fd4938a (diff) | |
| download | coinos-server-aa165827fdeba6bb4c0602f0a0168570d6379dd9.tar.gz coinos-server-aa165827fdeba6bb4c0602f0a0168570d6379dd9.zip | |
incremental location cache update
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/locations.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/locations.ts b/lib/locations.ts index 0faad2fc..122a6c3a 100644 --- a/lib/locations.ts +++ b/lib/locations.ts @@ -5,12 +5,11 @@ import { fields, pick } from "$lib/utils"; export let getLocations = async () => { try { - let last = await g("locations:last"); - let now = Date.now(); + let since = await g("locations:since"); + if (!since) since = "2022-09-19T00:00:00Z"; - if (now - last < 60000) return g("locations"); let locations: Array<any> = await got( - "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z", + `https://api.btcmap.org/v2/elements?updated_since=${since}`, ).json(); locations = locations.filter( @@ -37,8 +36,11 @@ export let getLocations = async () => { } } + let previous = await g("locations"); + locations.push(...previous); + await s("locations", locations); - await s("locations:last", now); + await s("locations:since", new Date().toISOString().split(".")[0] + "Z"); } catch (e) { err("problem fetching locations", e); } |
