a page that outranks kept ones takes their room, so a re-render that grows never drops a repo's front page, and every repo renders again once to get one back
Signed-off-by: dawn <90008@klbr.net>
3 unmodified lines456788910111263 unmodified lines3 unmodified linesimport path from "node:path";import { latestPath, ROUTES } from "./shared.mjs";
// a bump means no saved page can be trustedexport const RENDERER_FORMAT = 3;export const RENDERER_FORMAT = 4;
export const tokenOf = (did) => createHash("sha256").update(did).digest("hex").slice(0, 32);
// svfe's url for a repo's owner: the handle, or the did when it has none63 unmodified lines403 unmodified linesExpand all40440540640740840941041141241341441541641741841942042142242342442542642742842943043118 unmodified lines450451452453454455456457458258 unmodified linesExpand all403 unmodified linesExpand all }); const results = new Map(); let at = 0; let remainingKnown = wanted.filter((r) => r in pages).length; // a page that outranks kept ones takes their room, worst first: the budget keeps the best // ranked pages, also when a re-render of a kept page comes out bigger const makeRoom = (route, need, ready) => { const rank = rankOfRoute(route); const pending = new Set(wanted.slice(at)); const worse = Object.keys(pages) .filter((other) => !pending.has(other) && rankOfRoute(other) > rank) .sort((a, b) => rankOfRoute(b) - rankOfRoute(a) || (a < b ? 1 : -1)); const freed = worse.reduce((sum, other) => sum + pages[other].bytes, 0); if (bytes + need - freed > budget.bytes) return; for (const other of worse) { if (bytes + need <= budget.bytes) break; bytes -= pages[other].bytes; delete pages[other]; rendered.delete(other); overBudget.add(other); stats.dropped++; ready.push({ route: other, gz: null }); } }; const retire = () => { const ready = []; while (at < wanted.length && results.has(wanted[at])) { const route = wanted[at++];18 unmodified lines const prev = minViewBytes.get(parsed.view); if (prev === undefined || gz.length < prev) minViewBytes.set(parsed.view, gz.length); } } if (gz && bytes + gz.length + extra > budget.bytes) makeRoom(route, gz.length + extra, ready); if (!gz || bytes + gz.length + extra > budget.bytes) { if (known) { delete pages[route]; stats.dropped++;258 unmodified linesExpand all