Speed: member reads cached 15 s (cleared on every new chain event) so line, stats and positions stop repeating RPC round trips
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,7 +149,16 @@ async function memberIdByAccount(addr) {
|
||||
}
|
||||
async function memberCount() { return toNum(word(await call(SEL.memberCount), 0)); }
|
||||
async function productCount() { return toNum(word(await call(SEL.productCount), 0)); }
|
||||
// member reads are cached 15 s (2026-10-20): dashboards ask for the same members many times a minute and every read is
|
||||
// an RPC round trip; sponsor never changes and a buyer count up to 15 s old is fine for display
|
||||
const memberCache = new Map();
|
||||
async function member(id) {
|
||||
const hit = memberCache.get(Number(id)); if (hit && Date.now() - hit.at < 15000) return hit.v;
|
||||
const v = await memberRead(id); memberCache.set(Number(id), { at: Date.now(), v });
|
||||
if (memberCache.size > 5000) memberCache.clear();
|
||||
return v;
|
||||
}
|
||||
async function memberRead(id) {
|
||||
const r = await call(SEL.members, [id]);
|
||||
return { account: toAddr(word(r, 0)), sponsorId: toNum(word(r, 1)), buyerCount: toNum(word(r, 2)),
|
||||
activated: toNum(word(r, 3)) === 1, countedAsBuyer: toNum(word(r, 4)) === 1 };
|
||||
@@ -243,7 +252,7 @@ async function tail() {
|
||||
const ev = decodeLog(lg);
|
||||
if (!ev) continue;
|
||||
ev.ts = Date.now(); // indexed-at time: powers honest time-series charts
|
||||
state.events.push(ev);
|
||||
state.events.push(ev); memberCache.clear(); // a new chain event can change any member: drop the 15 s read cache
|
||||
tally(ev);
|
||||
if (onEvent) { try { onEvent(ev); } catch (e) { console.error('chain onEvent', e.message); } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user