aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-03 09:08:18 -0800
committerAdam Soltys <[email protected]>2026-03-03 09:08:18 -0800
commit94569349ea73685ae531ca0da91bfc3ff9d40c58 (patch)
treeab1595df08bc34a1cfe89867669e87c57ce238ca /lib
parentc7300714c57652e68fcadcdbcfcce3df8dd7d37b (diff)
downloadcoinos-server-94569349ea73685ae531ca0da91bfc3ff9d40c58.tar.gz
coinos-server-94569349ea73685ae531ca0da91bfc3ff9d40c58.zip
request tuning
Diffstat (limited to 'lib')
-rw-r--r--lib/db.ts24
1 files changed, 24 insertions, 0 deletions
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);