From 94569349ea73685ae531ca0da91bfc3ff9d40c58 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 3 Mar 2026 09:08:18 -0800 Subject: request tuning --- lib/db.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib') diff --git a/lib/db.ts b/lib/db.ts index 9d09c997..fbd7a6d8 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -104,6 +104,30 @@ export const gf = async (k) => { } }; +// Batch get with fallback to archive +export const gfAll = async (keys: string[]) => { + if (!keys.length) return []; + const values = await db.mGet(keys); + const missing: number[] = []; + for (let i = 0; i < values.length; i++) { + if (values[i] === null) missing.push(i); + } + if (missing.length) { + const archiveKeys = missing.map((i) => keys[i]); + const archiveValues = await archive.mGet(archiveKeys); + for (let j = 0; j < missing.length; j++) { + values[missing[j]] = archiveValues[j]; + } + } + return values.map((v) => { + try { + return JSON.parse(v as string); + } catch { + return v; + } + }); +}; + // lRange with fallback to archive for missing items export const lRangeWithArchive = async (k, start, end) => { const items = await db.lRange(k, start, end); -- cgit v1.2.3