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:
1 parent
0e52bf0e1b
commit
6ea611d949
6 files changed
+104
-24
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Frozen;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Chronos.Server.Hosting;
|
||||
|
||||
@@ -8,6 +9,12 @@ namespace Chronos.Server.Hosting;
|
||||
/// Serves the admin panel from embedded resources named <c>admin/…</c> (no build step, single-file friendly),
|
||||
/// with strong ETags, conditional GET and SPA fallback to <c>index.html</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every file, the modules included, is sent with <c>Cache-Control: no-cache</c>: the browser keeps it but asks again
|
||||
/// before each use, and an unchanged file costs a 304 without a body. The ETag is a hash of the content, so an upgrade
|
||||
/// changes the ETag of exactly the files it changed and a browser never runs new modules next to cached old ones (with
|
||||
/// <c>max-age</c> it could, until the cache expired).
|
||||
/// </remarks>
|
||||
public sealed class EmbeddedStaticFiles
|
||||
{
|
||||
private static readonly FrozenDictionary<string, string> ContentTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
@@ -55,9 +62,9 @@ public sealed class EmbeddedStaticFiles
|
||||
}
|
||||
var response = context.Response;
|
||||
response.Headers.ETag = file.ETag;
|
||||
response.Headers.CacheControl = path.EndsWith(".html", StringComparison.OrdinalIgnoreCase) ? "no-cache" : "public, max-age=3600";
|
||||
response.Headers.CacheControl = "no-cache";
|
||||
response.Headers.XContentTypeOptions = "nosniff";
|
||||
if (context.Request.Headers.IfNoneMatch == file.ETag)
|
||||
if (NoneMatchHolds(context.Request.Headers.IfNoneMatch, file.ETag))
|
||||
{
|
||||
response.StatusCode = StatusCodes.Status304NotModified;
|
||||
return true;
|
||||
@@ -67,4 +74,23 @@ public sealed class EmbeddedStaticFiles
|
||||
if (!HttpMethods.IsHead(context.Request.Method)) await response.Body.WriteAsync(file.Content, context.RequestAborted);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether an <c>If-None-Match</c> header names <paramref name="etag"/>: <c>*</c>, or one of its entity tags under the
|
||||
/// weak comparison GET uses (RFC 9110 §13.1.2), so a tag a proxy marked <c>W/</c> still matches.
|
||||
/// </summary>
|
||||
internal static bool NoneMatchHolds(StringValues header, string etag)
|
||||
{
|
||||
foreach (var value in header)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) continue;
|
||||
foreach (var part in value.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
if (part == "*") return true;
|
||||
var tag = part.StartsWith("W/", StringComparison.Ordinal) ? part[2..] : part;
|
||||
if (string.Equals(tag, etag, StringComparison.Ordinal)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user