From dd52dba479158946e1453b4cce4f3138fc93dddb Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 10:38:53 +0000 Subject: [PATCH] refactor(sync): queue download follow-ups through the job context Thumbnail and light-analysis jobs after a download now carry the user who started the download and are skipped when this engine cannot run them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.Data/Sync/SyncTransfers.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Titano.Data/Sync/SyncTransfers.cs b/src/Titano.Data/Sync/SyncTransfers.cs index 3fb1fa6b..5f0f356d 100644 --- a/src/Titano.Data/Sync/SyncTransfers.cs +++ b/src/Titano.Data/Sync/SyncTransfers.cs @@ -138,8 +138,8 @@ internal sealed class SyncTransfers(SyncService sync) if (sequenceId is { } downloaded && wanted.Count > restored) { var label = local!.DisplayTitle; - await EnqueueFollowUpAsync(ArchiveJobs.Thumbnails([downloaded], label), ct).ConfigureAwait(false); - await EnqueueFollowUpAsync(ProcessingJobs.LightAnalysis([downloaded], label), ct).ConfigureAwait(false); + await EnqueueFollowUpAsync(context, ArchiveJobs.Thumbnails([downloaded], label)).ConfigureAwait(false); + await EnqueueFollowUpAsync(context, ProcessingJobs.LightAnalysis([downloaded], label)).ConfigureAwait(false); } } @@ -451,19 +451,9 @@ internal sealed class SyncTransfers(SyncService sync) _ => [], }; - /// Puts a follow-up job in the queue; the engine claims it on its next poll. - private Task EnqueueFollowUpAsync(ArchiveJobRequest request, CancellationToken cancellationToken) => - sync.Database.Jobs.EnqueueAsync(new Job - { - Id = Guid.CreateVersion7(), - Kind = request.Kind, - TargetIds = request.Targets, - TargetLabel = request.Label, - ParametersJson = request.ParametersJson, - Priority = request.Priority, - State = JobState.Queued, - Created = DateTimeOffset.UtcNow, - }, cancellationToken); + /// Queues a follow-up on this job's engine for the same user; skipped when the engine has no handler for it. + private static Task EnqueueFollowUpAsync(JobContext context, ArchiveJobRequest request) => + context.EnqueueFollowUpAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority); private static void EnsureSpace(string root, long bytes) {