fix(admin): revalidate panel files, count bulk jobs, refresh every loaded row

The phase 3 packages land together, so the panel's pieces must stay in step:

- Admin files are served with Cache-Control: no-cache and their content
  ETag (If-None-Match lists, W/ tags and * honoured). With max-age=3600 a
  browser that loaded the panel before an upgrade could run new modules
  next to cached old ones for up to an hour; now it revalidates each file
  and only what the upgrade changed is sent again.
- The Library's Upload and a sequence's Add photos open upload.js, which
  now ships with the panel: the test requires the module (no 404), the
  dynamic import and the openUpload({ api, sequence, onDone }) calls.
- Bulk jobs over more than 1000 sequences queue one job per 1000; the
  toast now says how many were queued, also when a later chunk failed.
- The live refresh re-reads every loaded row, a thousand per request,
  instead of dropping rows beyond the first 1000 back to Load more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-27 11:08:47 +01:00
1 parent 0e52bf0e1b
commit 6ea611d949
6 files changed
+104 -24

No files matched your search

+24 -12
View File
@@ -187,20 +187,31 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
drawFoot();
}
/** The loaded rows again, as many as are shown (live updates); the selection and the keyboard place stay. */
/**
* The loaded rows again, as many as are shown (live updates), a thousand per request; the selection and the keyboard
* place stay.
*/
async function refreshVisible() {
const mine = ++generation;
const wanted = Math.max(rows.length, PAGE);
try {
const [page, f] = await Promise.all([
api.get(listQuery(Math.min(Math.max(rows.length, PAGE), BULK_LIMIT), null)),
api.get("/api/v1/sequences/facets").catch(() => facets),
]);
const facetsRead = api.get("/api/v1/sequences/facets").catch(() => facets);
const first = await api.get(listQuery(Math.min(wanted, BULK_LIMIT), null));
let items = first.items;
let after = first.nextCursor;
while (after && items.length < wanted) {
if (mine !== generation || !root.isConnected) return;
const page = await api.get(listQuery(Math.min(wanted - items.length, BULK_LIMIT), after));
items = items.concat(page.items);
after = page.nextCursor;
}
const f = await facetsRead;
if (mine !== generation || !root.isConnected) return;
total = page.total ?? total;
total = first.total ?? total;
facets = f;
drawFilters();
rows = page.items;
cursor = page.nextCursor;
rows = items;
cursor = after;
const known = new Set(rows.map((r) => r.id));
if (!matching) selection.set([...selection.ids].filter((id) => known.has(id)));
const focused = itemsHost.contains(document.activeElement);
@@ -378,9 +389,11 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
return [...selection.ids].map((id) => known.get(id)).filter(Boolean);
}
/** One job per thousand sequences (a bulk request's limit); the toast counts them, and says those queued before a failure. */
async function queueJobs(kind) {
let queued = 0;
let skipped = 0;
let failure = null;
try {
for (const ids of chunks([...selection.ids])) {
const result = await api.post("/api/v1/sequences/bulk/jobs", { ids, kind });
@@ -388,11 +401,10 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
skipped += result.skipped;
}
} catch (err) {
toast(errorText(err), true);
return;
failure = errorText(err);
}
toast([queued > 0 ? t("Admin.Library.JobQueued") : t("Admin.Library.NothingQueued"), skipped > 0 ? plural("Admin.Library.Skipped", skipped) : ""]
.filter(Boolean).join(" · "));
const done = queued > 0 ? plural("Admin.Library.JobsQueued", queued) : failure ? "" : t("Admin.Library.NothingQueued");
toast([done, skipped > 0 ? plural("Admin.Library.Skipped", skipped) : "", failure ?? ""].filter(Boolean).join(" · "), failure !== null);
}
async function retag() {