fix: conversions name, lock and settle as phase 4a's writers do

Phase 4b was built on phase 4a before its review fixes. Integrated on the reviewed 4a, the
conversion now follows the same rules as filing and the other writers.

- Names: a converted file is named as filing names a photo of its sequence (FrameNaming: the
  archive's file template, the frame's context in the sequence with its camera, lens, number
  and title, {name} the card's, {ext} the target's, a long name keeping its extension).
  Replace through ConvertOptions.FileName; New sequence through the ingest itself
  (StagedFrame.NamedAs), which numbers and names the copies in the new sequence. Names stay
  unique against every file present, those leaving included, so a Replace never moves onto a
  file; a test pins a stray file that keeps its bytes.
- Leases: stage A starts from the sidecar settled under the sequence's lease where the index
  has it then (SequenceWriter.ReadLocked), and FrameTrash.ReplaceAsync reads the row again
  under the lease, so a folder a Reorganize moved meanwhile is followed, never made again.
  A Reorganize the archive waits for keeps the conversion off its sequences (pinned).
- Journals: the replace journal is settled with the others. MassRenamer steps, restores into
  a sequence and sequence deletions wait for an unsettled replacement as they wait for a
  restore, and so do photo deletions, whose frames version the recovery reads
  (FrameTrash.EnsureReplaced); a scan settles it and reconciles nothing meanwhile; a restore
  settles its sequence's replace journal first, at the folder the index has under the lease.
- The convert job tells each sequence converted or made as it completes, as a Reorganize
  tells each step, so an editor open on it reads it again while the rest of the job runs.
- Desktop: JobKind.Convert gets its row in the settings' job priority list. A click on Apply
  that commits the quality no longer starts the same dry run again under the click (as 4a
  fixed for Reorganize).
- Panel: a dry run answered during the confirmation with the same plan no longer drops the
  confirmed Apply; a different plan is shown with Admin.Convert.PlanChanged (en, it).
- Tests: TrashDialogTests.EmptyQueuesTheJobOfTheConfirmedPlanOnly waits for the command to
  end before running it again (a running AsyncRelayCommand ignored the second Execute).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2e0d1d6dcc10575734970bb9c77749f00777c859)
This commit is contained in:
Alby96 committed 2026-10-27 22:03:07 +01:00
1 parent a1c1c21ebd
commit 341fb77507
22 files changed
+345 -91

No files matched your search

@@ -12,9 +12,9 @@ namespace Chronos.Data.Archiving.Jobs;
/// volume lacks the space, and converts one sequence at a time, each all or nothing; its journal makes every stage
/// resumable. Progress counts photos; the checkpoint only marks a resume, the journal says where. Each sequence whose frames
/// were replaced is told as <c>converted</c>, each new sequence as <c>created</c> (<see cref="ArchiveServiceOptions.SequenceChanged"/>),
/// and the passes they need (light analysis, a deep one when the source had it, thumbnails and proxies) are queued as
/// follow-ups. Sequences left as they were (changed after the plan, busy, a photo that failed) are logged and fail the job
/// at the end, after the others are converted; a retry tries them again.
/// as soon as it is done; the passes they need (light analysis, a deep one when the source had it, thumbnails and
/// proxies) are queued as follow-ups. Sequences left as they were (changed after the plan, busy, a photo that failed) are
/// logged and fail the job at the end, after the others are converted; a retry tries them again.
/// </summary>
internal sealed class ConvertJobHandler(ChronosDatabase db, MassConverter converter, Func<Guid, string, CancellationToken, Task>? sequenceChanged) : IJobHandler
{
@@ -39,11 +39,10 @@ internal sealed class ConvertJobHandler(ChronosDatabase db, MassConverter conver
var result = await converter.RunAsync(archive, parameters, context.Job.Id, by, new ConvertCallbacks(
(done, total) => context.ReportAsync(done, total),
(done, total) => context.CheckpointAsync(Checkpoint, done, total),
context.Log), context.Cancellation).ConfigureAwait(false);
context.Log, TellAsync), context.Cancellation).ConfigureAwait(false);
await QueueAsync(context, result).ConfigureAwait(false);
context.Log(Loc.L("Archive.Log.ConvertDone", result.Sequences.Count(s => s.Outcome == ConvertOutcome.Converted),
result.Sequences.Count(s => s.Outcome == ConvertOutcome.Created), result.Frames));
await TellAsync(result).ConfigureAwait(false);
var kept = result.Kept.Count();
if (kept > 0) throw new InvalidOperationException(Loc.Plural("Archive.Error.ConvertKept", kept));
}
@@ -65,27 +64,27 @@ internal sealed class ConvertJobHandler(ChronosDatabase db, MassConverter conver
}
}
/// <summary>Tells each sequence changed or made; a failure is logged, never passed on to the job.</summary>
private async Task TellAsync(ConvertResult result)
/// <summary>
/// Tells a sequence whose frames were replaced, or the one made, as soon as its outcome is journaled, while the rest of the
/// job runs (an editor open on it reads it again); a failure is logged, never passed on to the job.
/// </summary>
private async ValueTask TellAsync(ConvertSequenceResult sequence)
{
if (sequenceChanged is null) return;
foreach (var sequence in result.Sequences)
var (id, change) = sequence.Outcome switch
{
var (id, change) = sequence.Outcome switch
{
ConvertOutcome.Converted => (sequence.SequenceId, Converted),
ConvertOutcome.Created when sequence.NewSequenceId is { } made => (made, Created),
_ => (Guid.Empty, string.Empty),
};
if (id == Guid.Empty) continue;
try
{
await sequenceChanged(id, change, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Warning("archive", $"The change of sequence {id} was not told", ex);
}
ConvertOutcome.Converted => (sequence.SequenceId, Converted),
ConvertOutcome.Created when sequence.NewSequenceId is { } made => (made, Created),
_ => (Guid.Empty, string.Empty),
};
if (id == Guid.Empty) return;
try
{
await sequenceChanged(id, change, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Warning("archive", $"The change of sequence {id} was not told", ex);
}
}
}