Speed: catalog reads run in parallel and /api/catalog serves the cached ladder while refreshing in the background (was ~6 s of sequential chain reads on every 20 s miss); position rows read the chain side by side

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-19 15:30:30 -05:00
parent 0aa22e9984
commit 7af47ae921
2 changed files with 26 additions and 16 deletions
+9 -8
View File
@@ -162,15 +162,16 @@ async function product(id) {
async function quoteWei(id) { try { return toBig(word(await call(SEL.quoteWei, [id]), 0)); } catch (e) { return null; } }
async function creditBalance(id, type) { return Number(toBig(word(await call(SEL.creditBalance, [id, type || 0]), 0))); }
async function catalog() {
// products and quotes are read side by side, not one after another (2026-10-19: 15 sequential reads took ~6 s
// and every dashboard waited on them)
const n = await productCount();
const out = [];
for (let i = 1; i <= n; i++) {
const p = await product(i);
if (!p.exists || !p.active) continue;
const q = await quoteWei(i);
out.push(Object.assign(p, { costWei: q === null ? null : q.toString() }));
}
return out;
const ids = Array.from({ length: n }, (_, k) => k + 1);
const rows = await Promise.all(ids.map(async i => {
const [p, q] = await Promise.all([product(i), quoteWei(i)]);
if (!p.exists || !p.active) return null;
return Object.assign(p, { costWei: q === null ? null : q.toString() });
}));
return rows.filter(Boolean);
}
// ---- event decode ----