feat(settings): make every Settings row real; archive settings, index backups and restore

Settings (UI-01, UI-02, UI-03, UI-09, RF-4):
- New Import, Analysis and Formats pages, in the order of Settings.html. Import holds
  the defaults of new cards (session rules, subfolders, verification, duplicates,
  after-import actions); Analysis the deep-analysis width cap, night and star-field
  thresholds and deep analysis after import or scan; Formats the decode tier of every
  format on this PC with a notice and Store install link per missing codec extension.
- Archive gains thumbnail size and rescan interval; its templates, proxy size and
  thumbnail size are the open archive's own (archive.json) and new archives' defaults.
- Rendering quality, parallelism and background priority now drive the jobs: quality
  maps to preparation size, read-ahead and default flow quality; parallelism sets the
  engine's workers live and caps per-job threads; background priority raises the UI
  thread while Titano is in front.
- Advanced gains Restore (daily backups, dry-run summary, destructive confirmation,
  staged for the next start) and Reset all.
- The naming preview's sample title is a catalog string.

Engine (ENG-03, ENG-04, ENG-06):
- ArchiveService.GetSettingsAsync/UpdateSettingsAsync rewrite archive.json atomically
  under a lease, then the index row; the server endpoint and the desktop use them, and
  the desktop creates archives with Settings › Archive. ThumbnailPolicy in archive.json
  sizes the thumbnails.
- DatabaseBackups: daily VACUUM INTO copies kept x3 on the desktop and on a server on
  SQLite (DatabaseBackupService), staged restore checked and preceded by a fresh copy.
- Maintenance vacuums the SQLite index when 10 % or more is free (dry run reports it).
- JobEngine.SetWorkers; ProcessingOptions.Tune applies host tuning per job.

Archive setup toasts say why in a localized sentence (RF-1).

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 10:06:34 +00:00
1 parent c11c996bc6
commit 3e146c9f9f
91 files changed
+2864 -357

No files matched your search

+72 -7
View File
@@ -29,7 +29,8 @@ public sealed record JobEngineOptions
/// Persistent job queue runner (BRIEF §14.6): N workers claim queued jobs from the database by priority, run the
/// registered handler, checkpoint progress, and survive crashes (running jobs are requeued at start with their
/// checkpoints). Used by the desktop client (local mode) and the server. Jobs an <see cref="ISelectiveJobHandler"/>
/// declines stay queued for other claimers.
/// declines stay queued for other claimers. The number of workers can change while the engine runs
/// (<see cref="SetWorkers"/>, Settings › Rendering › Parallelism on the desktop).
/// </summary>
public sealed class JobEngine : IAsyncDisposable
{
@@ -48,16 +49,30 @@ public sealed class JobEngine : IAsyncDisposable
private readonly Channel<bool> _wake = Channel.CreateBounded<bool>(new BoundedChannelOptions(1) { FullMode = BoundedChannelFullMode.DropWrite });
private readonly CancellationTokenSource _shutdown = new();
private readonly List<Task> _workers = [];
private readonly Lock _workerGate = new();
private readonly HashSet<int> _activeWorkers = [];
private int _workerTarget;
private bool _workersStarted;
public JobEngine(TitanoDatabase db, IEnumerable<IJobHandler> handlers, JobEngineOptions? options = null)
{
_db = db;
Options = options ?? new JobEngineOptions();
_handlers = handlers.ToDictionary(h => h.Kind);
_workerTarget = Options.Workers;
}
public JobEngineOptions Options { get; }
/// <summary>Workers that claim jobs: <see cref="JobEngineOptions.Workers"/> until <see cref="SetWorkers"/> changes it.</summary>
public int Workers
{
get
{
lock (_workerGate) return _workerTarget;
}
}
/// <summary>A job changed state (queued, running, done, failed, cancelled, paused).</summary>
public event Action<Job>? JobChanged;
@@ -81,13 +96,33 @@ public sealed class JobEngine : IAsyncDisposable
Log.Info("jobs", "No job handlers; this engine claims nothing");
return;
}
for (var i = 0; i < Options.Workers; i++)
lock (_workerGate)
{
var id = Options.Workers == 1 ? Options.WorkerId : $"{Options.WorkerId}#{i}";
_workers.Add(Task.Run(() => WorkerLoopAsync(id, _shutdown.Token), CancellationToken.None));
_workersStarted = true;
for (var i = 0; i < _workerTarget; i++) StartWorker(i);
}
}
/// <summary>
/// Changes the number of workers. More start claiming at once; the surplus ones finish the job they are running
/// (never interrupted) and then stop. Before <see cref="StartAsync"/> it only sets how many start.
/// </summary>
public void SetWorkers(int count)
{
ArgumentOutOfRangeException.ThrowIfLessThan(count, 1);
lock (_workerGate)
{
if (_workerTarget == count) return;
_workerTarget = count;
if (_workersStarted)
{
for (var i = 0; i < count; i++) StartWorker(i);
}
}
Log.Info("jobs", $"Job engine set to {count} worker(s)");
Wake();
}
/// <summary>Queues a job and wakes a worker.</summary>
public async Task<Job> EnqueueAsync(JobKind kind, IReadOnlyList<Guid> targets, string? targetLabel = null, string? parametersJson = null,
JobPriority priority = JobPriority.Normal, Guid? createdBy = null, CancellationToken cancellationToken = default)
@@ -129,10 +164,17 @@ public sealed class JobEngine : IAsyncDisposable
public async ValueTask DisposeAsync()
{
Task[] workers;
lock (_workerGate)
{
// No worker starts any more: the shutdown token is about to be disposed.
_workersStarted = false;
workers = [.. _workers];
}
await _shutdown.CancelAsync().ConfigureAwait(false);
try
{
await Task.WhenAll(_workers).ConfigureAwait(false);
await Task.WhenAll(workers).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@@ -181,11 +223,34 @@ public sealed class JobEngine : IAsyncDisposable
if (await _db.Jobs.GetAsync(id, cancellationToken).ConfigureAwait(false) is { } job) JobChanged?.Invoke(job);
}
/// <summary>Claims and runs jobs until shutdown. Nothing a job or a handler throws ends the worker.</summary>
private async Task WorkerLoopAsync(string workerId, CancellationToken shutdown)
/// <summary>Starts worker <paramref name="index"/> unless it runs already; call under <see cref="_workerGate"/>.</summary>
private void StartWorker(int index)
{
if (!_activeWorkers.Add(index)) return;
// A single worker keeps the plain id (as before workers could be added); numbered ones get "#n".
var id = index == 0 && Options.Workers == 1 ? Options.WorkerId : $"{Options.WorkerId}#{index}";
var shutdown = _shutdown.Token;
_workers.Add(Task.Run(() => WorkerLoopAsync(index, id, shutdown), CancellationToken.None));
}
/// <summary>True when worker <paramref name="index"/> is beyond the wanted count; it is then no longer active.</summary>
private bool Retires(int index)
{
lock (_workerGate)
{
if (index < _workerTarget) return false;
_activeWorkers.Remove(index);
return true;
}
}
/// <summary>Claims and runs jobs until shutdown, or until <see cref="SetWorkers"/> no longer wants this worker.
/// Nothing a job or a handler throws ends the worker.</summary>
private async Task WorkerLoopAsync(int index, string workerId, CancellationToken shutdown)
{
while (!shutdown.IsCancellationRequested)
{
if (Retires(index)) return;
Job? job;
try
{