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:
@@ -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 ----
|
||||
|
||||
Reference in New Issue
Block a user