From 6186159954646b92f1efdbb5c8f0ffa26e29e0ab Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 21 Sep 2026 19:44:24 -0700 Subject: parse: cache node aliases as a small map with a working timestamp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- routes/payments.ts | 22 +++++++++++++--------- 1 file 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]); -- cgit v1.2.3