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
@@ -1,5 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
@@ -93,6 +95,44 @@ public sealed partial class SystemEndpointTests(TestContext context)
|
||||
Assert.Equal(HttpStatusCode.NotModified, cached.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AdminPanelFilesAreRevalidatedSoAnUpgradeNeverMixesOldAndNewModules()
|
||||
{
|
||||
// A browser that kept app.js from before an upgrade must not run it next to a new ui.js: every file is kept but
|
||||
// asked for again before each use, and its ETag follows its content, so only what the upgrade changed is sent.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
foreach (var path in new[] { "/admin/", "/admin/app.js", "/admin/ui.js", "/admin/admin.css", "/admin/icons.js", "/admin/pages/library.js", "/admin/upload.js" })
|
||||
{
|
||||
using var response = await server.Client.GetAsync(path);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode, path);
|
||||
var cache = Assert.NotNull(response.Headers.CacheControl);
|
||||
Assert.True(cache.NoCache && cache.MaxAge is null && !cache.Public, $"{path}: {cache}");
|
||||
var etag = Assert.NotNull(response.Headers.ETag);
|
||||
Assert.False(etag.IsWeak, path);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
Assert.Equal($"\"{Convert.ToHexString(SHA256.HashData(bytes).AsSpan(0, 12))}\"", etag.Tag, path);
|
||||
|
||||
foreach (var sent in new[] { etag, new EntityTagHeaderValue(etag.Tag, isWeak: true), EntityTagHeaderValue.Any })
|
||||
{
|
||||
using var again = new HttpRequestMessage(HttpMethod.Get, path);
|
||||
again.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"0123\""));
|
||||
again.Headers.IfNoneMatch.Add(sent);
|
||||
using var notModified = await server.Client.SendAsync(again);
|
||||
Assert.Equal(HttpStatusCode.NotModified, notModified.StatusCode, $"{path} with {sent}");
|
||||
Assert.Equal(etag, notModified.Headers.ETag, path);
|
||||
Assert.True(Assert.NotNull(notModified.Headers.CacheControl).NoCache, path);
|
||||
}
|
||||
|
||||
// A file the browser holds from another build has another ETag: the new content comes back.
|
||||
using var stale = new HttpRequestMessage(HttpMethod.Get, path);
|
||||
stale.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"0123456789ABCDEF01234567\""));
|
||||
using var fresh = await server.Client.SendAsync(stale);
|
||||
Assert.Equal(HttpStatusCode.OK, fresh.StatusCode, path);
|
||||
var resent = await fresh.Content.ReadAsByteArrayAsync();
|
||||
Assert.BytesEqual(bytes, resent, path);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PlainHttpFromAnotherMachineGoesToThePublicHttpsPort()
|
||||
{
|
||||
@@ -150,10 +190,10 @@ public sealed partial class SystemEndpointTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AdminPanelListsTheLibraryAndLoadsTheWebUploadOnlyWhenItIsThere()
|
||||
public async Task AdminPanelListsTheLibraryAndLoadsTheWebUploadOnDemand()
|
||||
{
|
||||
// Owner review 2, R6: the Library comes right after the Dashboard. The web upload (R3) is a module of its own that the
|
||||
// Library imports on demand, so the panel works with or without it.
|
||||
// Library imports on demand (Upload, and a sequence's Add photos), so a page that never uploads never loads it.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var app = await server.Client.GetStringAsync("/admin/app.js");
|
||||
var top = MenuPages(app)[0];
|
||||
@@ -175,11 +215,11 @@ public sealed partial class SystemEndpointTests(TestContext context)
|
||||
foreach (Match import in StaticImport().Matches(source))
|
||||
Assert.True(Resolve(folder, import.Groups[1].Value) != "upload.js", $"{module} imports upload.js statically");
|
||||
}
|
||||
using var upload = await server.Client.GetAsync("/admin/upload.js");
|
||||
if (upload.StatusCode == HttpStatusCode.OK)
|
||||
Assert.True(Regex.IsMatch(await upload.Content.ReadAsStringAsync(), @"export (?:async )?function openUpload\("), "upload.js exports openUpload");
|
||||
else
|
||||
Assert.Equal(HttpStatusCode.NotFound, upload.StatusCode);
|
||||
// The module the dynamic import names is there (no 404 in the browser) and exports what the Library calls.
|
||||
Assert.Equal("upload.js", Resolve("pages/", "../upload.js"));
|
||||
Assert.True(Regex.IsMatch(modules["upload.js"], @"export (?:async )?function openUpload\(\{ api, sequence, onDone \}"), "upload.js exports openUpload({ api, sequence, onDone })");
|
||||
Assert.Contains("openUpload({ api, onDone: ", modules["pages/library.js"]);
|
||||
Assert.Contains("openUpload({ api, sequence: seq, onDone: ", modules["pages/library/sequence.js"]);
|
||||
}
|
||||
|
||||
/// <summary>The admin panel's modules from app.js and the menu's pages along their static imports, with their source.</summary>
|
||||
|
||||
Reference in new issue
Block a user