diff options
| author | Adam Soltys <[email protected]> | 2026-09-21 19:44:24 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-21 19:44:24 -0700 |
| commit | 6186159954646b92f1efdbb5c8f0ffa26e29e0ab (patch) | |
| tree | 6d78cfb13bdafb079c8bac80710fbd7536e2d7a6 | |
| parent | 23c8b11bd3c1dee56781cc83e65e077409c0858e (diff) | |
| download | coinos-server-6186159954646b92f1efdbb5c8f0ffa26e29e0ab.tar.gz coinos-server-6186159954646b92f1efdbb5c8f0ffa26e29e0ab.zip | |
parse: cache node aliases as a small map with a working timestamp
The alias cache stored the full listnodes output as an array and hung its
`last` stamp on that array, which JSON.stringify drops, and the refresh
condition was inverted besides. Net effect: every lightning send page view
refetched all ~16k nodes and rewrote ~10MB to the db. Keep only the
id→alias map with a real timestamp and refresh it hourly.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
| -rw-r--r-- | routes/payments.ts | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/routes/payments.ts b/routes/payments.ts index 6ae88475..9bdcc2eb 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -217,14 +217,19 @@ export default { user, } = req; try { + // Node alias lookup, refreshed hourly. Only the id→alias map is kept: + // the old code stored the full listnodes output (~10MB for 16k nodes) + // as an array, so the `last` stamp it hung on the array was dropped by + // JSON.stringify and the condition was inverted anyway — every send + // page view refetched and rewrote the whole thing. const hour = 1000 * 60 * 60; - let nodes = await g("nodes"); - const { last } = nodes || {}; - - if (!last || last > Date.now() - hour) { - ({ nodes } = await ln.listnodes()); - nodes.last = Date.now(); - await s("nodes", nodes); + let cache = await g("nodes"); + if (!cache?.aliases || !cache.last || cache.last < Date.now() - hour) { + const { nodes } = await ln.listnodes(); + const aliases = {}; + for (const n of nodes) if (n.alias) aliases[n.nodeid] = n.alias; + cache = { last: Date.now(), aliases }; + await s("nodes", cache); } const decoded = await ln.decode(payreq); @@ -240,8 +245,7 @@ export default { decoded); } else ({ amount_msat, payee } = decoded); - const node = nodes.find((n) => n.nodeid === payee); - const alias = node ? node.alias : (payee || "").substr(0, 12); + const alias = cache.aliases[payee] || (payee || "").substr(0, 12); const amount = Math.round((amount_msat || 0) / 1000); let ourfee = Math.round(amount * config.fee[PaymentType.lightning]); |
