fix(analysis): follow-ups skip queued sequences; photos added by a scan are analysed again
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
6 files changed
+75
-10
No files matched your search
@@ -160,7 +160,11 @@ public sealed class ArchiveIndexer
|
||||
if (reconcile || File.Exists(sequence.IngestJournalPath))
|
||||
{
|
||||
var before = manifest;
|
||||
manifest = await _writer.UpdateAsync(paths, manifest.Id, folder.RelativeFolder, m => SequenceAdopter.Reconcile(sequence, m, cancellationToken),
|
||||
// Photos added, gone or back: the light analysis no longer describes the frames, so the scan's follow-up runs it again.
|
||||
manifest = await _writer.UpdateAsync(paths, manifest.Id, folder.RelativeFolder,
|
||||
m => SequenceAdopter.Reconcile(sequence, m, cancellationToken) is { } reconciled
|
||||
? reconciled with { Status = reconciled.Status & ~SequenceStatus.AnalyzedLight }
|
||||
: null,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
if (!ReferenceEquals(before, manifest)) bytes = null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
new ScanJobHandler(_db, Indexer, JobKind.Scan),
|
||||
new ScanJobHandler(_db, Indexer, JobKind.Rebuild),
|
||||
new VerifyJobHandler(_db, Verifier),
|
||||
new ImportJobHandler(Imports),
|
||||
new ImportJobHandler(_db, Imports),
|
||||
new ImageJobHandler(_db, Images, JobKind.Thumbs),
|
||||
new ImageJobHandler(_db, Images, JobKind.Proxies),
|
||||
new MaintenanceJobHandler(_db, Maintenance),
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Titano.Data.Archiving.Jobs;
|
||||
/// number of plan items done. A removed card fails the job at a batch boundary; resuming it after re-insertion
|
||||
/// continues there. The sequences the import went into are then queued for light analysis.
|
||||
/// </summary>
|
||||
internal sealed class ImportJobHandler(ImportService imports) : IJobHandler
|
||||
internal sealed class ImportJobHandler(TitanoDatabase db, ImportService imports) : IJobHandler
|
||||
{
|
||||
public JobKind Kind => JobKind.Import;
|
||||
|
||||
@@ -30,6 +30,6 @@ internal sealed class ImportJobHandler(ImportService imports) : IJobHandler
|
||||
.ConfigureAwait(false);
|
||||
}, p => context.ReportAsync(p.BytesDone, p.BytesTotal, p.Current), context.Cancellation).ConfigureAwait(false);
|
||||
context.Log(Loc.L("Archive.Log.ImportDone", final.Copied, final.Skipped, final.Failed));
|
||||
await AnalysisFollowUp.QueueAsync(context, await imports.SequencesOfAsync(parameters, context.Cancellation).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
await AnalysisFollowUp.QueueAsync(db, context, await imports.SequencesOfAsync(parameters, context.Cancellation).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ internal static class JobArchive
|
||||
/// <summary>
|
||||
/// <see cref="JobKind.Scan"/> (incremental, or full with <see cref="ScanParameters.Full"/>) and
|
||||
/// <see cref="JobKind.Rebuild"/>. Checkpoint: <c>after:<folder></c>, the last folder indexed. When anything was
|
||||
/// indexed, the sequences never light-analysed (adopted folders, new sidecars) are queued for it.
|
||||
/// indexed, the sequences without a current light analysis (adopted folders, new sidecars, photos added to a folder) are
|
||||
/// queued for it.
|
||||
/// </summary>
|
||||
internal sealed class ScanJobHandler(TitanoDatabase db, ArchiveIndexer indexer, JobKind kind) : IJobHandler
|
||||
{
|
||||
@@ -41,7 +42,7 @@ internal sealed class ScanJobHandler(TitanoDatabase db, ArchiveIndexer indexer,
|
||||
context.Log(Loc.L("Archive.Log.ScanDone", summary.Folders, summary.Indexed, summary.Adopted, summary.Removed));
|
||||
// A resumed scan may have indexed its folders before the interruption.
|
||||
if (summary.Indexed > 0 || resume is not null)
|
||||
await AnalysisFollowUp.QueueAsync(context, await AnalysisFollowUp.UnanalysedAsync(db, archive.Id, context.Cancellation).ConfigureAwait(false))
|
||||
await AnalysisFollowUp.QueueAsync(db, context, await AnalysisFollowUp.UnanalysedAsync(db, archive.Id, context.Cancellation).ConfigureAwait(false))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,24 @@ namespace Titano.Data.Processing;
|
||||
/// <summary>
|
||||
/// Light analysis queued after work that brings sequences or frames into the index (card import, adoption, scan), so the
|
||||
/// advisor's Auto values and recommended preset exist without any user action (BRIEF §1.1, §4.3). Nothing is queued
|
||||
/// when the engine cannot run light analysis.
|
||||
/// when the engine cannot run light analysis, and a sequence already waiting in a queued light analysis is not queued
|
||||
/// again (that job runs after the changes that led here).
|
||||
/// </summary>
|
||||
internal static class AnalysisFollowUp
|
||||
{
|
||||
/// <summary>Queues one light analysis of <paramref name="sequenceIds"/> (labelled like the job that found them).</summary>
|
||||
public static async Task QueueAsync(JobContext context, IReadOnlyCollection<Guid> sequenceIds)
|
||||
public static async Task QueueAsync(TitanoDatabase db, JobContext context, IReadOnlyCollection<Guid> sequenceIds)
|
||||
{
|
||||
if (sequenceIds.Count == 0) return;
|
||||
var request = ProcessingJobs.LightAnalysis([.. sequenceIds], context.Job.TargetLabel);
|
||||
var waiting = (await db.Jobs.ListQueuedAsync([JobKind.LightAnalyse], 1000, context.Cancellation).ConfigureAwait(false))
|
||||
.SelectMany(j => j.TargetIds).ToHashSet();
|
||||
var targets = sequenceIds.Where(id => !waiting.Contains(id)).Distinct().ToList();
|
||||
if (targets.Count == 0) return;
|
||||
var request = ProcessingJobs.LightAnalysis(targets, context.Job.TargetLabel);
|
||||
await context.EnqueueFollowUpAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>Sequences of <paramref name="archiveId"/> that were never light-analysed (new or adopted ones).</summary>
|
||||
/// <summary>Sequences of <paramref name="archiveId"/> without a current light analysis (new, adopted, or with frames a scan added).</summary>
|
||||
public static async Task<List<Guid>> UnanalysedAsync(TitanoDatabase db, Guid archiveId, CancellationToken cancellationToken)
|
||||
{
|
||||
var ids = new List<Guid>();
|
||||
|
||||
Reference in new issue
Block a user