diff options
| author | Adam Soltys <[email protected]> | 2026-03-03 09:08:18 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-03 09:08:18 -0800 |
| commit | 94569349ea73685ae531ca0da91bfc3ff9d40c58 (patch) | |
| tree | ab1595df08bc34a1cfe89867669e87c57ce238ca /lib | |
| parent | c7300714c57652e68fcadcdbcfcce3df8dd7d37b (diff) | |
| download | coinos-server-94569349ea73685ae531ca0da91bfc3ff9d40c58.tar.gz coinos-server-94569349ea73685ae531ca0da91bfc3ff9d40c58.zip | |
request tuning
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/db.ts | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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); |
