Famous people: a page without its portrait is not cached; the admin list refreshes
CI / test (push) Successful in 1m57s
CI / build (push) Skipped
CI / deploy (push) Skipped

The worker does not clear the page cache when the portrait is done, so a
page loaded right after publishing showed "hamarosan elkészül" for five
minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-22 16:59:07 +00:00
co-authored by Claude Opus 5.5
parent 37cb0abf4b
commit 2997a06474
2 changed files with 18 additions and 3 deletions
@@ -2,7 +2,7 @@
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { BirthForm } from "@/app/profil/BirthForm";
import { api, errorText } from "@/lib/api";
@@ -24,11 +24,19 @@ export function AdminCelebrities() {
const [adding, setAdding] = useState(false);
const [subtitle, setSubtitle] = useState("");
useEffect(() => {
const load = useCallback(() => {
api<{ celebrities: AdminCelebrityRow[] }>("/admin/celebrities")
.then((r) => setRows(r.celebrities))
.catch((e) => setError(errorText(e)));
}, []);
useEffect(load, [load]);
// A portrait being written: look again now and then.
const writing = rows?.some((c) => c.analysis_status === "pending" || c.analysis_status === "running");
useEffect(() => {
if (!writing) return;
const t = setInterval(load, 10_000);
return () => clearInterval(t);
}, [writing, load]);
return (
<section className="field" style={{ gap: 18 }}>
+8 -1
View File
@@ -24,7 +24,14 @@ export const loadCelebrity = cache(async (slug: string): Promise<PublicCelebrity
const res = await fetch(`${BACKEND_URL}/v1/public/celebrities/${slug}`, {
next: { revalidate: 300, tags: [CELEBRITIES_TAG] },
});
if (res.ok) return (await res.json()) as PublicCelebrity;
if (res.ok) {
const c = (await res.json()) as PublicCelebrity;
if (c.analysis) return c;
// The portrait is still being written (the worker does not clear the
// cache when it is done): no cached copy until it is there.
const fresh = await fetch(`${BACKEND_URL}/v1/public/celebrities/${slug}`, { cache: "no-store" });
return fresh.ok ? ((await fresh.json()) as PublicCelebrity) : c;
}
if (res.status !== 404) throw new Error(`celebrity ${slug}: HTTP ${res.status}`);
const token = (await cookies()).get(SESSION_COOKIE)?.value;
if (!token) return null;