Dashboard freshness: bust the member cache on every indexed chain event + drop browser cache to 15s - joins/upgrades now visible on next page load instead of up to 2-3 min later

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-08-19 14:52:03 -05:00
parent 6ebe436cf3
commit ac5d29fc6e
+6 -1
View File
@@ -386,7 +386,7 @@ async function handleApi(req,res,pathname){
const id=Number(new URL(req.url,'http://x').searchParams.get('id')||0); const id=Number(new URL(req.url,'http://x').searchParams.get('id')||0);
if(!Number.isInteger(id)||id<1||id>281474976710655)return json(res,400,{error:'Enter a numeric member ID.'}); if(!Number.isInteger(id)||id<1||id>281474976710655)return json(res,400,{error:'Enter a numeric member ID.'});
const cached=memberCache.get(id); const cached=memberCache.get(id);
if(cached&&Date.now()-cached.ts<120000)return json(res,200,cached.data,{'Cache-Control':'public, max-age=60'}); if(cached&&Date.now()-cached.ts<120000)return json(res,200,cached.data,{'Cache-Control':'public, max-age=15'});
try{ try{
const r=await Promise.race([chain.memberPublic(id),new Promise((_,rej)=>setTimeout(()=>rej(new Error('Blockchain lookup timed out — try again.')),20000))]); const r=await Promise.race([chain.memberPublic(id),new Promise((_,rej)=>setTimeout(()=>rej(new Error('Blockchain lookup timed out — try again.')),20000))]);
if(r.registered)r.referralUrl=`${getConfig().dappReferralBaseUrl}${encodeURIComponent(id)}`; if(r.registered)r.referralUrl=`${getConfig().dappReferralBaseUrl}${encodeURIComponent(id)}`;
@@ -778,6 +778,11 @@ function checkUpgradeAlerts(){
setInterval(checkUpgradeAlerts, 5*60*1000).unref(); setInterval(checkUpgradeAlerts, 5*60*1000).unref();
setTimeout(checkUpgradeAlerts, 30000).unref(); setTimeout(checkUpgradeAlerts, 30000).unref();
chain.startIndexer(evt=>{ chain.startIndexer(evt=>{
// Any on-chain event makes cached member views stale (the new member, the
// sponsor, every upline's team/pipeline/coach data). Events are infrequent;
// just drop the whole member cache so dashboards reflect joins/upgrades on
// the next fetch instead of up to 2 minutes later.
try{memberCache.clear();}catch(e){}
try{ try{
const c=getConfig(); const c=getConfig();
// teamRootId accepts a comma list ("21,136") — alerts fire for ANY listed org // teamRootId accepts a comma list ("21,136") — alerts fire for ANY listed org