fix(archive): partial writers keep the folder changed for the scan; image flags follow queued passes and hashed photos
Writers that change part of a sequence (decode tiers, image-pass flags, analyses, verify flushes and stamps, duplicate flags, title/tags/rating/ notes edits, mass rename) now ask ArchiveIndexer.InStepAsync before their own sidecar write and record the folder's scan stamps afterwards only when the index held the folder as it was: the stored stamps are still the folder's and the row holds the sidecar's frames. What another process changed in the sidecar alone (frames, a new title) stays visible to the next incremental scan, which writes the whole row from the sidecar. EditSequenceInfoAsync reads sidecar and row under the lease and writes the row through SequenceRepository.EditAsync at the settings version it read, applying the edit again on a conflict, then the sidecar from the stored row; settings and frames committed meanwhile stay. MassRenamer writes only folder and title (RelocateAsync, whose null title now keeps the current one). Verify flushes and duplicate flags run under one lease. A scan that finds frames another writer listed in the sidecar itself clears AnalyzedLight, ThumbsBuilt and ProxiesBuilt only in its own row and only on a server (ImagesAfterScan); the shared sidecar keeps the writer's flags, so a desktop's poll no longer makes the server redo its passes. An image pass overtaken by an upload keeps its flag while a pass of the same kind is queued for the sequence. ThumbPack.IsFrom accepts a thumbnail drawn before a verify hashed its photo, in the pass, in SameFrames and in the server's thumbnail lookup, which answered 404 for every such frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
18 files changed
+532
-116
No files matched your search
@@ -10,6 +10,7 @@ public sealed record FolderScanState(string Folder, Guid? SequenceId, FileStamp?
|
||||
public sealed class ArchiveRepository
|
||||
{
|
||||
private const string Columns = "id, name, root_path, folder_template, file_template, schema_version, created, proxy_long_edge";
|
||||
private const string FolderStateSelect = "SELECT folder, sequence_id, sidecar_size, sidecar_ticks, photos_ticks FROM archive_folders";
|
||||
|
||||
private static readonly string UpsertSql = SqlDialect.Upsert("archives",
|
||||
["id", "name", "root_path", "folder_template", "file_template", "schema_version", "created", "proxy_long_edge"], 1);
|
||||
@@ -39,15 +40,14 @@ public sealed class ArchiveRepository
|
||||
/// <summary>Scan stamps of every folder of an archive, by folder.</summary>
|
||||
public async Task<IReadOnlyDictionary<string, FolderScanState>> GetFolderStatesAsync(Guid archiveId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var rows = await _db.ListAsync(
|
||||
"SELECT folder, sequence_id, sidecar_size, sidecar_ticks, photos_ticks FROM archive_folders WHERE archive_id = $1", [archiveId],
|
||||
r => new FolderScanState(r.GetString(0), r.GetGuidOrNull(1),
|
||||
r.GetInt64OrNull(3) is { } sidecar ? new FileStamp(r.GetInt64(2), new DateTime(sidecar, DateTimeKind.Utc)) : null,
|
||||
r.GetInt64OrNull(4) is { } photos ? new FileStamp(0, new DateTime(photos, DateTimeKind.Utc)) : null),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
var rows = await _db.ListAsync($"{FolderStateSelect} WHERE archive_id = $1", [archiveId], MapFolderState, cancellationToken).ConfigureAwait(false);
|
||||
return rows.ToDictionary(s => s.Folder, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>Scan stamps of one folder of an archive; null when none are recorded.</summary>
|
||||
public Task<FolderScanState?> GetFolderStateAsync(Guid archiveId, string folder, CancellationToken cancellationToken = default) =>
|
||||
_db.SingleAsync($"{FolderStateSelect} WHERE archive_id = $1 AND folder = $2", [archiveId, folder], MapFolderState, cancellationToken);
|
||||
|
||||
public async Task SetFolderStateAsync(Guid archiveId, FolderScanState state, CancellationToken cancellationToken = default) =>
|
||||
await _db.ExecuteAsync(FolderStateUpsertSql,
|
||||
[archiveId, state.Folder, state.SequenceId, state.Sidecar?.Size, state.Sidecar?.ModifiedUtc.Ticks, state.Photos?.ModifiedUtc.Ticks, DateTimeOffset.UtcNow],
|
||||
@@ -61,6 +61,10 @@ public sealed class ArchiveRepository
|
||||
public Task<int> ClearFolderStatesAsync(Guid archiveId, CancellationToken cancellationToken = default) =>
|
||||
_db.ExecuteAsync("DELETE FROM archive_folders WHERE archive_id = $1", [archiveId], cancellationToken);
|
||||
|
||||
private static FolderScanState MapFolderState(DbRow r) => new(r.GetString(0), r.GetGuidOrNull(1),
|
||||
r.GetInt64OrNull(3) is { } sidecar ? new FileStamp(r.GetInt64(2), new DateTime(sidecar, DateTimeKind.Utc)) : null,
|
||||
r.GetInt64OrNull(4) is { } photos ? new FileStamp(0, new DateTime(photos, DateTimeKind.Utc)) : null);
|
||||
|
||||
private static Archive Map(DbRow r) => new()
|
||||
{
|
||||
Id = r.GetGuid(0),
|
||||
|
||||
@@ -408,19 +408,23 @@ public sealed class SequenceRepository
|
||||
[archiveId, sessionKey], cancellationToken).ConfigureAwait(false))!.Value;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>Moves a sequence to another folder and/or title (mass rename); false when it does not exist.</summary>
|
||||
/// <summary>
|
||||
/// Moves a sequence to another folder and, with <paramref name="title"/>, retitles it (mass rename; settings version
|
||||
/// + 1 when the title changes); every other field stays as the locked row has it. False when it does not exist.
|
||||
/// </summary>
|
||||
/// <param name="title">The new title; null keeps the current one.</param>
|
||||
public Task<bool> RelocateAsync(Guid id, string folder, string? title, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
var current = await session.QuerySingleOrDefaultAsync($"{_select} WHERE s.id = $1{_db.Sql.ForUpdate}", [id], Map, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (current is null) return false;
|
||||
var titleChanged = current.Title != title;
|
||||
var retitled = title is not null && current.Title != title;
|
||||
await UpsertRowAsync(session, current with
|
||||
{
|
||||
Folder = folder,
|
||||
Title = title,
|
||||
SettingsVersion = titleChanged ? current.SettingsVersion + 1 : current.SettingsVersion,
|
||||
Title = retitled ? title : current.Title,
|
||||
SettingsVersion = retitled ? current.SettingsVersion + 1 : current.SettingsVersion,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user