diff options
| author | Adam Soltys <[email protected]> | 2026-01-22 18:48:07 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-01-22 18:48:07 -0800 |
| commit | d147e04d1b52f1359507a6f9d88e0227cf6bb250 (patch) | |
| tree | 2eb562735a335831cec4737610f9638aaf50f32f /routes | |
| parent | 0edd59be4bbfc62f73b972e4992ec3c31d6baab1 (diff) | |
| download | coinos-server-d147e04d1b52f1359507a6f9d88e0227cf6bb250.tar.gz coinos-server-d147e04d1b52f1359507a6f9d88e0227cf6bb250.zip | |
read payments from archive
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/payments.ts | 23 | ||||
| -rw-r--r-- | routes/users.ts | 12 |
2 files changed, 24 insertions, 11 deletions
diff --git a/routes/payments.ts b/routes/payments.ts index d4d83bd2..a61c4c3c 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -1,7 +1,7 @@ import config from "$config"; import api from "$lib/api"; import { requirePin } from "$lib/auth"; -import { db, g, s } from "$lib/db"; +import { archive, db, g, gf, s } from "$lib/db"; import { generate } from "$lib/invoices"; import { replay } from "$lib/lightning"; import ln from "$lib/ln"; @@ -112,15 +112,28 @@ export default { offset = Number.parseInt(offset) || 0; const range = !limit || received || start || end ? -1 : limit - 1; - let payments = (await db.lRange(`${aid || id}:payments`, 0, range)) || []; + const listKey = `${aid || id}:payments`; + let payments = (await db.lRange(listKey, 0, range)) || []; + + if (range === -1) { + const archived = (await archive.lRange(listKey, 0, -1)) || []; + payments = [...new Set([...payments, ...archived])]; + } else if (limit) { + const needed = Math.max(0, limit + offset - payments.length); + if (needed > 0) { + const archived = + (await archive.lRange(listKey, 0, limit + offset - 1)) || []; + payments = [...new Set([...payments, ...archived])]; + } + } payments = ( await Promise.all( payments.map(async (pid) => { - const p = await g(`payment:${pid}`); + const p = await gf(`payment:${pid}`); if (!p) { warn("user", id, "missing payment", pid); - await db.lRem(`${aid || id}:payments`, 0, pid); + await db.lRem(listKey, 0, pid); return p; } if (received && p.amount < 0) return; @@ -237,7 +250,7 @@ export default { if (typeof amount === "undefined" || amount === null) return bail(res, "fund not found"); let payments = (await db.lRange(`fund:${id}:payments`, 0, -1)) || []; - payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); + payments = await Promise.all(payments.map((hash) => gf(`payment:${hash}`))); await Promise.all( payments.map(async (p: any) => (p.user = await getUser(p.uid, fields))), diff --git a/routes/users.ts b/routes/users.ts index 91928503..8cb24870 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -2,7 +2,7 @@ import { createReadStream } from "node:fs"; import { appendFile, unlink, writeFile } from "node:fs/promises"; import config from "$config"; import { requirePin } from "$lib/auth"; -import { db, g, ga, s } from "$lib/db"; +import { db, g, ga, gf, s } from "$lib/db"; import { err, l, warn } from "$lib/logging"; import { mail, templates } from "$lib/mail"; import { getNostrUser, getProfile, serverPubkey2 } from "$lib/nostr"; @@ -109,7 +109,7 @@ export default { let total = 0; for (const pid of payments) { - const p = await g(`payment:${pid}`); + const p = await gf(`payment:${pid}`); if (!p) continue; total += p.amount; if (p.amount < 0) @@ -571,7 +571,7 @@ export default { for (const { ref } of ( await Promise.all( - payments.reverse().map(async (id) => await g(`payment:${id}`)), + payments.reverse().map(async (id) => await gf(`payment:${id}`)), ) ).filter((p) => p && p.type === PaymentType.internal && p.ref)) { if (ref === id) continue; @@ -950,8 +950,8 @@ export default { const payments = await Promise.all( pids.map(async (pid) => { - const p = await g(`payment:${pid}`); - p.user = await g(`user:${p.uid}`); + const p = await gf(`payment:${pid}`); + if (p) p.user = await g(`user:${p.uid}`); return p; }), ); @@ -976,7 +976,7 @@ export default { const pids = await db.lRange(`${a.pubkey}:payments`, 0, -1); let payments = await Promise.all( - pids.map((pid) => g(`payment:${pid}`)), + pids.map((pid) => gf(`payment:${pid}`)), ); payments = payments.filter((p) => p); a.spent = payments.reduce( |
