fix(archive): scans leave sequences waiting for a folder alone and build server images

A sequence created through POST /api/v1/sequences keeps an empty folder until its
first frame. Scans no longer adopt loose photos at the archive root under its id,
and a rebuild, the orphans report and fix, verify and the scan follow-ups no longer
treat it as the root sequence, as missing or as a sequence to analyse. All of them
use ArchiveIngest.AwaitsFolder.

On the server (ArchiveServiceOptions.ImagesAfterScan), a scan that indexes sequences
without thumbnails or proxies queues background Thumbs and Proxies passes for them,
as an upload does. A scan that finds photos added or removed clears ThumbsBuilt and
ProxiesBuilt together with AnalyzedLight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 15:58:37 +00:00
1 parent 32a0e9bbc1
commit fba05c2840
10 files changed
+290 -29

No files matched your search

@@ -3,6 +3,7 @@ using Titano.Core.Import;
using Titano.Core.Model;
using Titano.Data.Archiving;
using Titano.Data.Archiving.Jobs;
using Titano.Data.Jobs;
using Titano.Data.Repositories;
using Titano.Testing;
using static Titano.Data.Tests.Archiving.ArchiveFixture;
@@ -40,6 +41,9 @@ public sealed class ArchiveJobTests(TestContext context)
var rebuild = await engine.EnqueueAsync(ArchiveJobs.Rebuild(fx.Archive), cancellationToken: fx.Ct);
await fx.WaitForAsync(rebuild.Id, JobState.Done);
Assert.Equal(2, (await LocationsAsync(fx)).Count);
// The desktop decodes its thumbnails on demand and makes proxies when asked.
Assert.Empty((await fx.Db.Jobs.ListAsync(null, JobKind.Thumbs, cancellationToken: fx.Ct)).Items);
Assert.Empty((await fx.Db.Jobs.ListAsync(null, JobKind.Proxies, cancellationToken: fx.Ct)).Items);
}
[Test]
@@ -88,6 +92,56 @@ public sealed class ArchiveJobTests(TestContext context)
Assert.Contains("made 3, reused 3", done.LogTail);
}
[Test]
public async Task AServerScanQueuesThumbnailsAndProxiesOfTheSequencesItIndexesWithoutThem()
{
await using var fx = await CreateAsync(context);
Populate(fx);
// The server's archive engine (ArchiveModule); the desktop's scans queue no image passes.
var service = new ArchiveService(fx.Db, new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20), ImagesAfterScan = true });
await using var engine = new JobEngine(fx.Db, service.CreateJobHandlers(),
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
await engine.StartAsync(fx.Ct);
var scan = await engine.EnqueueAsync(ArchiveJobs.Scan(fx.Archive), cancellationToken: fx.Ct);
await fx.WaitForAsync(scan.Id, JobState.Done);
var locations = await LocationsAsync(fx);
var first = new Dictionary<JobKind, Guid>();
foreach (var kind in new[] { JobKind.Thumbs, JobKind.Proxies })
{
var pass = (await fx.Db.Jobs.ListAsync(null, kind, cancellationToken: fx.Ct)).Items.Single();
Assert.SequenceEqual(locations.Select(l => l.Id), pass.TargetIds);
Assert.Equal(JobPriority.Background, pass.Priority);
await fx.WaitForAsync(pass.Id, JobState.Done);
first[kind] = pass.Id;
}
foreach (var location in locations) Assert.True(Built((await fx.Db.Sequences.GetAsync(location.Id))!.Status), location.Folder);
// Every folder indexed again, but none without its images: nothing is queued.
var full = await engine.EnqueueAsync(ArchiveJobs.Scan(fx.Archive, full: true), cancellationToken: fx.Ct);
await fx.WaitForAsync(full.Id, JobState.Done);
Assert.Count(1, (await fx.Db.Jobs.ListAsync(null, JobKind.Thumbs, cancellationToken: fx.Ct)).Items);
Assert.Count(1, (await fx.Db.Jobs.ListAsync(null, JobKind.Proxies, cancellationToken: fx.Ct)).Items);
// A photo added to a folder: its sequence lacks the images of that frame until the passes queued for it alone ran.
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "a"), Start.AddMinutes(5), 1, firstSeed: 90, firstNumber: 7);
var added = await engine.EnqueueAsync(ArchiveJobs.Scan(fx.Archive), cancellationToken: fx.Ct);
await fx.WaitForAsync(added.Id, JobState.Done);
var a = locations.Single(l => l.Folder == "a");
foreach (var kind in new[] { JobKind.Thumbs, JobKind.Proxies })
{
var pass = (await fx.Db.Jobs.ListAsync(null, kind, cancellationToken: fx.Ct)).Items.Single(j => j.Id != first[kind]);
Assert.SequenceEqual([a.Id], pass.TargetIds);
await fx.WaitForAsync(pass.Id, JobState.Done);
}
Assert.True(Built((await fx.Db.Sequences.GetAsync(a.Id))!.Status), "built again");
using var pack = ThumbPackReader.Open(fx.Paths.Sequence("a").ThumbsPackPath);
Assert.Count(7, pack.Entries);
Assert.Count(7, Directory.GetFiles(fx.Paths.Sequence("a").Proxies));
static bool Built(SequenceStatus status) => status.HasFlag(SequenceStatus.ThumbsBuilt) && status.HasFlag(SequenceStatus.ProxiesBuilt);
}
[Test]
public async Task AThumbnailPassFlagsFramesNothingDecodesAndClearsThemOnceTheyDecode()
{