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:
10 files changed
+290
-29
No files matched your search
@@ -17,6 +17,24 @@ public sealed class ArchiveIngestTests(TestContext context)
|
||||
Guid? sequenceId = null, string? title = null, string name = "IMG_0001.JPG") =>
|
||||
new(fx.Archive.Id, sequenceId, title, sequenceId is null && title is null ? sessionKey : null, staged.Path, name, staged.Size, staged.Sha256, null, null);
|
||||
|
||||
/// <summary>A sequence as <c>POST /api/v1/sequences</c> creates it: a row without a folder or frames.</summary>
|
||||
private static async Task<Sequence> CreateWithoutPhotosAsync(ArchiveFixture fx, string title)
|
||||
{
|
||||
var created = new Sequence
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArchiveId = fx.Archive.Id,
|
||||
Title = title,
|
||||
Folder = string.Empty,
|
||||
Rating = 4,
|
||||
Origin = SequenceOrigin.Server,
|
||||
OwnerUserId = Guid.CreateVersion7(),
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
await fx.Db.Sequences.UpsertAsync(created, fx.Ct);
|
||||
return created;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASessionKeyCreatesOneSequenceNamedByTheTemplates()
|
||||
{
|
||||
@@ -242,6 +260,80 @@ public sealed class ArchiveIngestTests(TestContext context)
|
||||
Assert.FileExists(staged.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceWaitingForItsFirstFrameNeverLendsItsIdToTheArchiveRoot()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
|
||||
// Loose photos at the root, which a scan adopts in place.
|
||||
Photos.WriteSeries(fx.Archive.RootPath, Start.AddDays(-1), 2);
|
||||
|
||||
await fx.ScanAsync();
|
||||
|
||||
var root = ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath);
|
||||
Assert.NotEqual(waiting.Id, root.Id);
|
||||
var rootRow = (await fx.Db.Sequences.GetAsync(root.Id))!;
|
||||
Assert.Equal((string.Empty, 2), (rootRow.Folder, rootRow.FrameCount));
|
||||
var row = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
|
||||
Assert.Equal((string.Empty, 0, "Harbour sunset"), (row.Folder, row.FrameCount, row.Title));
|
||||
|
||||
// Its first frame still gets a folder of its own, and the root keeps its photos.
|
||||
var first = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start, 1), sequenceId: waiting.Id), fx.Ct);
|
||||
Assert.Equal(waiting.Id, first.SequenceId);
|
||||
var placed = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
|
||||
Assert.Equal(("2026/2026-09-28 Canon EOS R5", 1), (placed.Folder, placed.FrameCount));
|
||||
Assert.Equal(root.Id, ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath).Id);
|
||||
Assert.Equal(2, (await fx.Db.Sequences.GetAsync(root.Id))!.FrameCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARootSequenceWhoseSidecarIsGoneIsAdoptedAgainUnderItsOwnId()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
Photos.WriteSeries(fx.Archive.RootPath, Start, 2);
|
||||
await fx.ScanAsync();
|
||||
var adopted = Assert.NotNull((await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct)).SingleOrDefault());
|
||||
// Created later, so its id sorts after the root sequence's.
|
||||
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
|
||||
File.Delete(fx.Paths.Sequence(string.Empty).ManifestPath);
|
||||
|
||||
await fx.ScanAsync();
|
||||
|
||||
Assert.Equal(adopted.Id, ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath).Id);
|
||||
Assert.Equal(2, (await fx.Db.Sequences.GetAsync(adopted.Id))!.FrameCount);
|
||||
var row = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
|
||||
Assert.Equal((string.Empty, 0), (row.Folder, row.FrameCount));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RebuildOrphansAndVerifyLeaveASequenceWaitingForItsFirstFrame()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
Photos.WriteSeries(Path.Combine(fx.Archive.RootPath, "Trips", "Comet"), Start, 2);
|
||||
await fx.ScanAsync();
|
||||
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
|
||||
|
||||
// It has no sidecar yet, which is no reason to drop it.
|
||||
var rebuilt = await fx.ScanAsync(ScanMode.Rebuild);
|
||||
Assert.Equal(0, rebuilt.Removed);
|
||||
var orphans = await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct);
|
||||
Assert.Empty(orphans.MissingSequences);
|
||||
Assert.Empty(orphans.UnindexedFolders);
|
||||
Assert.Equal(0, await fx.Service.RemoveMissingSequencesAsync(fx.Archive.Id, [waiting.Id], fx.Ct));
|
||||
var report = await fx.Service.Verifier.VerifyAsync(fx.Archive, null, default, (_, _, _) => ValueTask.CompletedTask, null, fx.Ct);
|
||||
Assert.Equal((1, 2L), (report.Sequences, report.Checked));
|
||||
var kept = Assert.NotNull(await fx.Db.Sequences.GetAsync(waiting.Id));
|
||||
Assert.Equal(("Harbour sunset", 4), (kept.Title, kept.Rating));
|
||||
|
||||
// The archive root is not its folder: loose photos there are a folder the index does not know yet.
|
||||
Photos.WriteSeries(fx.Archive.RootPath, Start.AddDays(-1), 1, firstSeed: 50);
|
||||
Assert.SequenceEqual([string.Empty], (await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct)).UnindexedFolders);
|
||||
|
||||
var first = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddDays(1), 1), sequenceId: waiting.Id), fx.Ct);
|
||||
Assert.Equal(waiting.Id, first.SequenceId);
|
||||
Assert.Equal("2026/2026-09-29 Canon EOS R5", (await fx.Db.Sequences.GetAsync(waiting.Id))!.Folder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FramesInsertedBeforeOthersTakeTheProjectPositionsAlong()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user