Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 1d518763a42394d6e9c07706a426921fabc00d38
parent 9035e9d58c0c01f6d16a3ee580b10bf036394a79
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 02:33:11 -0400

umtool: deletes land on Work; the links and pieces caches live on globalThis

A delete cleared the links cache in its route's bundle only, so Work (another
bundle) listed the deleted piece for up to 15 s. Same fix as P2a's project
cache. Article and project deletes push Work's address directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/components/articles/DeleteArticle.tsx | 5+++--
Mumtool/components/projects/DeleteProject.tsx | 3++-
Mumtool/e2e/article-delete.spec.ts | 16+++++++++-------
Mumtool/lib/articles/links.mjs | 28+++++++++++++++++++---------
Mumtool/lib/pieces.ts | 12++++++++----
5 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/umtool/components/articles/DeleteArticle.tsx b/umtool/components/articles/DeleteArticle.tsx @@ -2,10 +2,11 @@ import { useRouter } from "next/navigation"; import DeletePlan from "@/components/DeletePlan"; +import { articlesHref } from "@/lib/hrefs"; // "Delete article" on an article of the store (release 27 follow-up): the // plan, then the registry's delete (POST /api/articles/delete); done, back to -// the article list, which says what went. +// the articles on Work, which says what went. export default function DeleteArticle({ article, published }: { article: string; published: boolean }) { const router = useRouter(); return ( @@ -15,7 +16,7 @@ export default function DeleteArticle({ article, published }: { article: string; endpoint="/api/articles/delete" body={{ article }} forceLabel={published ? "unpublish it first, then delete" : "delete anyway"} - onDone={(a) => router.push(`/articles?deleted=${encodeURIComponent(article)}&freed=${a.plan.bytes}`)} + onDone={(a) => router.push(articlesHref({ deleted: article, freed: String(a.plan.bytes) }))} /> ); } diff --git a/umtool/components/projects/DeleteProject.tsx b/umtool/components/projects/DeleteProject.tsx @@ -2,6 +2,7 @@ import { useRouter } from "next/navigation"; import DeletePlan from "@/components/DeletePlan"; +import { workHref } from "@/lib/hrefs"; // "Delete project" (release 27 follow-up): the plan, then the delete (POST // /api/projects/delete, lib/report/delete.mjs); done, back to the projects. @@ -13,7 +14,7 @@ export default function DeleteProject({ project }: { project: string }) { subject={`the project ${project}`} endpoint="/api/projects/delete" body={{ project }} - onDone={() => router.push(`/work?deleted=${encodeURIComponent(project)}`)} + onDone={() => router.push(workHref({ deleted: project }))} /> ); } diff --git a/umtool/e2e/article-delete.spec.ts b/umtool/e2e/article-delete.spec.ts @@ -94,13 +94,15 @@ test("an iteration: the current one and a parent are refused with the reason; a await expect(all.getByRole("list", { name: "what goes" })).toContainText("reports/omega/"); await expect(all.getByRole("list", { name: "what goes" })).toContainText("gen-projects/omega/i1/"); await all.getByRole("button", { name: "Confirm delete" }).click(); - await expect(page).toHaveURL(/\/articles\?deleted=omega/); - await expect(page.locator("[data-article='articles/omega']")).toHaveCount(0); + // /articles?deleted= rides its redirect to Work (kind=article). + await expect(page).toHaveURL(/\/work\?.*deleted=omega/); + await expect(page.locator("[data-deleted='omega']")).toContainText("Deleted omega"); + await expect(page.locator("[data-piece='a:articles/omega']")).toHaveCount(0); expect(existsSync(path.join(ARTICLES, "omega"))).toBe(false); expect(existsSync(path.join(PROJECTS, "omega")), "the emptied projects folder goes too").toBe(false); }); -test("an article in the making is deleted from its page, and /articles says so", async ({ page }) => { +test("an article in the making is deleted from its page, and Work says so", async ({ page }) => { await page.goto("/articles/psi"); await expect(page.locator("[data-article-meta] [data-status]")).toHaveAttribute("data-status", "pending"); await page.getByRole("button", { name: "Delete article" }).click(); @@ -108,9 +110,9 @@ test("an article in the making is deleted from its page, and /articles says so", await expect(plan.getByRole("list", { name: "what goes" })).toContainText("reports/psi/"); await plan.getByRole("button", { name: "Confirm delete" }).click(); - await expect(page).toHaveURL(/\/articles\?deleted=psi/); + await expect(page).toHaveURL(/\/work\?.*deleted=psi/); await expect(page.locator("[data-deleted='psi']")).toContainText("Deleted psi"); - await expect(page.locator("[data-pending-article='psi']")).toHaveCount(0); + await expect(page.locator("[data-piece='a:articles/psi']")).toHaveCount(0); expect(existsSync(path.join(ARTICLES, "psi"))).toBe(false); }); @@ -138,8 +140,8 @@ test("a take the project's manifest is, is refused until forced; another take an const plan = page.getByRole("region", { name: "delete the project reports/delete-fixture" }); await expect(plan.getByRole("list", { name: "what goes" })).toContainText("reports/delete-fixture"); await plan.getByRole("button", { name: "Confirm delete" }).click(); - await expect(page).toHaveURL(/\/browse\?deleted=reports%2Fdelete-fixture/); + await expect(page).toHaveURL(/\/work\?deleted=reports%2Fdelete-fixture/); await expect(page.locator("[data-deleted='reports/delete-fixture']")).toContainText("Deleted reports/delete-fixture"); - await expect(page.locator("[data-project='reports/delete-fixture']")).toHaveCount(0); + await expect(page.locator("[data-piece='p:reports/delete-fixture']")).toHaveCount(0); expect(existsSync(PROJECT)).toBe(false); }); diff --git a/umtool/lib/articles/links.mjs b/umtool/lib/articles/links.mjs @@ -38,13 +38,23 @@ import { kindLinksArticles } from "../projects/kinds.mjs"; import { idKeys } from "./sources.mjs"; const CACHE_MS = 30_000; -/** @type {Map<string, { at: number, value: Promise<any[]> }>} */ -const cache = new Map(); -/** @type {Map<string, { at: number, value: Promise<Map<string, any[]>> }>} */ -const iterCache = new Map(); -// Bumped by every clearLinksCache(), so a memo built from these reads (the -// pieces list, lib/pieces.ts) is dropped by the same writes that drop them. -let epoch = 0; +// The caches live on globalThis, not in module scope: Next bundles each route +// with its own copy of this module, so a clear from an API route (a delete) +// never reached the page rendered next (the P2a project-cache lesson, +// lib/projects.ts). One store per process. +/** + * @type {{ + * cache: Map<string, { at: number, value: Promise<any[]> }>, + * iterCache: Map<string, { at: number, value: Promise<Map<string, any[]>> }>, + * epoch: number, + * }} + */ +const STORE = (globalThis.__umtoolLinksCache ??= { cache: new Map(), iterCache: new Map(), epoch: 0 }); +const cache = STORE.cache; +const iterCache = STORE.iterCache; +// STORE.epoch is bumped by every clearLinksCache(), so a memo built from these +// reads (the pieces list, lib/pieces.ts) is dropped by the same writes that +// drop them. /** `~/x` back to an absolute path. */ export function untildify(p) { @@ -91,11 +101,11 @@ export function videoProjects(reportsRoot = REPORTS_ROOT) { export function clearLinksCache() { cache.clear(); iterCache.clear(); - epoch += 1; + STORE.epoch += 1; } /** How many times the links cache has been cleared: a memo built on it compares this. */ -export const linksCacheEpoch = () => epoch; +export const linksCacheEpoch = () => STORE.epoch; const NUMERIC = /^[1-9][0-9]*$/; diff --git a/umtool/lib/pieces.ts b/umtool/lib/pieces.ts @@ -89,21 +89,25 @@ export type PieceGraph = { }; const MEMO_MS = 15_000; -let memo: { at: number; epoch: number; value: Promise<PieceGraph> } | null = null; +type Memo = { at: number; epoch: number; value: Promise<PieceGraph> }; +// On globalThis, not in module scope: each Next bundle has its own copy of this +// module, and the epoch it compares (links.mjs) is per process. +const MEMO = ((globalThis as { __umtoolPieces?: { memo: Memo | null } }).__umtoolPieces ??= { memo: null }); /** Drop the memo (a test, or a write that changed what an article links). */ export function clearPiecesCache(): void { - memo = null; + MEMO.memo = null; } export function readPieceGraph(): Promise<PieceGraph> { const epoch = linksCacheEpoch(); + const memo = MEMO.memo; if (memo && memo.epoch === epoch && Date.now() - memo.at < MEMO_MS) return memo.value; const value = buildGraph(); const entry = { at: Date.now(), epoch, value }; - memo = entry; + MEMO.memo = entry; value.catch(() => { - if (memo === entry) memo = null; + if (MEMO.memo === entry) MEMO.memo = null; }); return value; }