fix(archive): server scans queue one image pass per sequence

A batched Thumbs or Proxies pass stopped at the first sequence whose folder
was renamed, deleted or damaged before the pass ran, and the others kept no
images until an administrator retried it. Each indexed sequence now gets its
own background pass, labelled with its title and de-duplicated against a
queued pass of its own, as after an upload.

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 16:29:32 +00:00
1 parent ed5c0c71c8
commit bb7546b2ea
2 files changed
+87 -28

No files matched your search

@@ -22,8 +22,8 @@ internal static class JobArchive
/// indexed, the sequences without a current light analysis (adopted folders, new sidecars, photos added to a folder) are
/// queued for it, and for a background deep analysis too when <see cref="ScanParameters.DeepAnalysis"/> asks. On the
/// server (<paramref name="imagesAfterScan"/>, <see cref="ArchiveServiceOptions.ImagesAfterScan"/>) the sequences it indexed
/// without thumbnails or proxies are queued for them too, as after an upload. Sequences waiting for their first frame
/// (<see cref="ArchiveIngest.AwaitsFolder"/>) have nothing to analyse or draw yet and are left out.
/// without thumbnails or proxies are queued for them too, one pass per sequence as after an upload. Sequences waiting for
/// their first frame (<see cref="ArchiveIndexer.AwaitingFolderAsync"/>) have nothing to analyse or draw yet and are left out.
/// </summary>
internal sealed class ScanJobHandler(TitanoDatabase db, ArchiveIndexer indexer, JobKind kind, bool imagesAfterScan = false) : IJobHandler
{
@@ -65,29 +65,33 @@ internal sealed class ScanJobHandler(TitanoDatabase db, ArchiveIndexer indexer,
}
/// <summary>
/// Queues one background <paramref name="pass"/> (thumbnails or proxies) of the sequences this run indexed whose
/// Queues a background <paramref name="pass"/> (thumbnails or proxies) of each sequence this run indexed whose
/// <paramref name="built"/> flag is clear: new and adopted sequences, and those whose photos changed (the scan clears the
/// flag then). After a resumed run, which may have indexed sequences before the interruption, every sequence of the
/// archive without the flag but those in <paramref name="awaiting"/>. Sequences already waiting in a queued pass of that
/// kind are left out.
/// flag then). After a resumed run, which may have indexed sequences before the interruption, of every sequence of the
/// archive without the flag but those in <paramref name="awaiting"/>. One pass per sequence, as after an upload: a folder
/// renamed, deleted or damaged before its pass runs fails that pass alone, and the other sequences still get their
/// images. A sequence whose own pass of that kind is already queued is left out.
/// </summary>
private async Task QueueImagesAsync(JobContext context, Archive archive, JobKind pass, SequenceStatus built, IReadOnlyList<Guid> indexed,
bool resumed, IReadOnlySet<Guid> awaiting)
{
var missing = new HashSet<Guid>();
var missing = new Dictionary<Guid, Sequence>();
var query = new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = built, Sort = SequenceSort.Oldest, Limit = 1000 };
do
{
var page = await db.Sequences.ListAsync(query, context.Cancellation).ConfigureAwait(false);
missing.UnionWith(page.Items.Select(s => s.Id));
foreach (var sequence in page.Items) missing[sequence.Id] = sequence;
query = query with { Cursor = page.NextCursor };
}
while (query.Cursor is not null);
missing.ExceptWith(awaiting);
var waiting = (await db.Jobs.ListQueuedAsync([pass], 1000, context.Cancellation).ConfigureAwait(false)).SelectMany(j => j.TargetIds).ToHashSet();
var targets = (resumed ? missing : indexed.Where(missing.Contains)).Where(id => !waiting.Contains(id)).Distinct().ToList();
if (targets.Count == 0) return;
var request = pass == JobKind.Thumbs ? ArchiveJobs.Thumbnails(targets, context.Job.TargetLabel) : ArchiveJobs.Proxies(targets, context.Job.TargetLabel);
await context.EnqueueFollowUpAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority).ConfigureAwait(false);
var targets = resumed ? missing.Values.ToList() : indexed.Distinct().Where(missing.ContainsKey).Select(id => missing[id]).ToList();
foreach (var sequence in targets)
{
if (awaiting.Contains(sequence.Id) || await db.Jobs.IsQueuedAsync(pass, sequence.Id, context.Cancellation).ConfigureAwait(false)) continue;
var request = pass == JobKind.Thumbs
? ArchiveJobs.Thumbnails([sequence.Id], sequence.DisplayTitle)
: ArchiveJobs.Proxies([sequence.Id], sequence.DisplayTitle);
await context.EnqueueFollowUpAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority).ConfigureAwait(false);
}
}
}