diff --git a/server.js b/server.js index a026bdc..ff5aaf0 100644 --- a/server.js +++ b/server.js @@ -88,6 +88,7 @@ async function uplineSlides(email, depth = 3) { // positions 2 and 3 become theirs at 2 and 5 qualifying buyers (the same // thresholds that open payout levels 2 and 3). Until then, or while an unlocked // slot is empty, the slot shows an upline's banner, then a house ad. +const catalogCache = { at: 0, products: null }; const wallUnlockedFor = bc => (bc >= 5 ? 3 : bc >= 2 ? 2 : 1); // every on-chain member id this session controls: the main wallet plus linked // positions (Qualified Start). Credits pool across them on the dashboard. @@ -545,7 +546,13 @@ const server = http.createServer(async (req, res) => { return json(res, 200, { url: 'https://www.moonpay.com/buy/pol', signed: false, pol }); } if (p === '/api/catalog' && req.method === 'GET') { - return json(res, 200, { products: await chain.catalog() }); + // five live quotes per call: serve a 20-second cache so pages that load the + // ladder (join, home, buy) are not waiting on the RPC every time + if (!catalogCache.at || Date.now() - catalogCache.at > 20000) { + try { catalogCache.products = await chain.catalog(); catalogCache.at = Date.now(); } + catch (e) { if (!catalogCache.products) throw e; } + } + return json(res, 200, { products: catalogCache.products }); } if (p === '/api/feed' && req.method === 'GET') { return json(res, 200, { events: await attachNames(chain.recentEvents(Number(u.searchParams.get('n')) || 100)) });