fix(settings): restore before the index opens; archive rows edit only their archive; parallelism follows the brief

Index restore (ENG-06, UI-09):
- A staged restore now runs on the files before the index is opened, so it also
  recovers an index that no longer opens; Settings > Advanced > Restore works
  without an open index (the current one is shown as unreadable).
- The staged copy passes PRAGMA quick_check (before migration, in a scratch copy)
  ahead of any backup: a damaged copy is set aside as .failed and never renews the
  daily copies. The index it replaces is kept as a VACUUM INTO copy, or, when it
  cannot be read, copied whole with its WAL as titano-replaced-<stamp>.db outside the
  rotation. The staged file is renamed over the index, so it is never applied twice.
- Archive > Maintenance gains Restore database..., which opens Settings > Advanced.

Archive settings (UI-03, ENG-03):
- An archive.json with an empty or overlong name (drive roots) can be edited again:
  the name read is made usable as at creation.
- Proxy and thumbnail sizes outside the presets (an admin's 3840) are listed and
  shown with their number.
- Changing the archive folder retargets the rows: an archive there is registered
  and rescanned; with none, the rows edit only the defaults of new archives. The
  rows never fall back to another archive of the index.
- Reset all and Import settings no longer rewrite the shared archive.json; Archive >
  Reset section asks first, naming the archive.
- PUT /api/v1/archive/settings: 409 archive_busy on a lease conflict, 409
  archive_manifest for a damaged, newer or foreign archive.json (was 500).

Parallelism (UI-02):
- Auto is the job engine's default, half the logical cores (BRIEF 14.6), with each
  job's own decode and analysis threads; a value the user sets is the number of
  workers and caps those threads. The memory budget is shared: each job's frame
  window gets budget / workers.

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 11:06:27 +00:00
1 parent 3e146c9f9f
commit 56aa4da674
63 files changed
+484 -179

No files matched your search

+12 -8
View File
@@ -188,7 +188,7 @@ public sealed class AppServices : IAsyncDisposable
if (_pollTimer is { } timer && timer.Period != ScanInterval) timer.Period = ScanInterval;
}
/// <summary>Workers of this PC's job engine (Settings › Rendering › Parallelism, Auto: cores minus four).</summary>
/// <summary>Workers of this PC's job engine (Settings › Rendering › Parallelism, Auto: half the logical cores).</summary>
public int Parallelism => ProcessingTuning.Parallelism(Settings, System.Environment.ProcessorCount);
/// <summary>Starts, restarts or stops the render node to match the opt-in, the server session and the trusted certificates (BRIEF §14.7).</summary>
@@ -206,10 +206,12 @@ public sealed class AppServices : IAsyncDisposable
/// <summary>
/// Opens (or creates) the index at <paramref name="databasePath"/>, migrates it (after a restore staged in Settings ›
/// Advanced replaced it), starts the job engine and the daily backups.
/// Advanced replaced it, which needs no open index: it also recovers one that no longer opens), starts the job engine
/// and the daily backups.
/// </summary>
public async Task OpenAsync(string databasePath, CancellationToken ct = default)
{
await RestoreStagedAsync(databasePath, ct);
try
{
Database = await Task.Run(() => TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(databasePath), ct), ct);
@@ -221,7 +223,6 @@ public sealed class AppServices : IAsyncDisposable
Log.Error("app", "The index could not be opened", ex);
return;
}
await RestoreStagedAsync(Database, ct);
await StartJobsAsync(Database, startEngine: true, ct);
Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
Devices.Start();
@@ -286,15 +287,18 @@ public sealed class AppServices : IAsyncDisposable
}
}
/// <summary>A restore staged in Settings › Advanced replaces the index before anything reads it (<see cref="StagedRestore"/>).</summary>
private async Task RestoreStagedAsync(TitanoDatabase database, CancellationToken ct)
/// <summary>
/// A restore staged in Settings › Advanced replaces the index file before the index is opened, so it also recovers an
/// index that no longer opens (<see cref="StagedRestore"/>).
/// </summary>
private async Task RestoreStagedAsync(string databasePath, CancellationToken ct)
{
try
{
if (await Task.Run(() => DatabaseBackups.RestoreStagedAsync(database, Environment.BackupDirectory, ct), ct))
if (await Task.Run(() => DatabaseBackups.RestoreStagedAsync(databasePath, Environment.BackupDirectory, ct), ct))
{
StagedRestore = StagedRestoreResult.Restored;
Log.Info("app", $"Index restored (schema {database.SchemaVersion})");
Log.Info("app", $"Index at {databasePath} restored from the staged copy");
}
}
catch (InvalidDataException ex)
@@ -302,7 +306,7 @@ public sealed class AppServices : IAsyncDisposable
StagedRestore = StagedRestoreResult.Unreadable;
Log.Error("app", "The staged index copy failed its checks; it was set aside and the index kept", ex);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException)
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException or DllNotFoundException)
{
StagedRestore = StagedRestoreResult.Deferred;
Log.Error("app", "The staged index restore could not run; the index was kept and the restore stays staged", ex);