fix(sync): send wanted proxies of unverified originals and recount them

Wanted proxies were matched to this PC's originals by SHA-256 only, and
frames adopted from a folder stay unhashed until verified. A desktop that
uploaded an adopted HEIC folder counted none of the proxies the server asked
for, showed the link in sync and sent none of them. The upload now keeps the
hash it computes for each original the index has none for and makes the
proxies from those too; the comparison counts a wanted frame no hash matched
against an unhashed original this PC reads by size (the server names its copy
by its own template, so not by name).

The wanted count was recomputed only when frame or render counters moved, so
proxies a render node sent left the row "Local ahead" with an upload that
sent nothing, and proxies the server started asking for later were never
counted. A link whose copy may make proxies for the server now keeps the
server's update time of the last comparison (sync_links.diff_remote_updated_at,
migration 0006) and is compared again when it moved.

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:53 +00:00
1 parent f215b99ca5
commit 17311cc459
9 files changed
+198 -18

No files matched your search

+29 -4
View File
@@ -134,16 +134,41 @@ public static class SyncRules
/// <summary>
/// Frames whose proxy the server asks for (it cannot decode their originals, BRIEF §2.3) that this PC holds and its
/// <paramref name="decoder"/> reads: an upload makes and sends them.
/// <paramref name="decoder"/> reads: an upload makes and sends them. A local original not hashed yet (a folder adopted
/// and not verified) stands for a wanted frame of its size that no hash matched (by size, not name: the server names
/// its copy by its own template); the upload hashes it before making the proxy.
/// </summary>
public static int ProxiesToSend(SequenceManifest manifest, IReadOnlyCollection<Frame> local, ImageDecoder decoder)
{
ArgumentNullException.ThrowIfNull(manifest);
var readable = local.Where(f => !string.IsNullOrEmpty(f.Sha256) && !ArchiveImages.NeedsProxy(decoder, f.Format))
.Select(f => f.Sha256!.ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
return manifest.Frames.Count(f => f.WantsProxy && readable.Contains(f.Sha256.ToLowerInvariant()));
var hashed = local.Where(f => !string.IsNullOrEmpty(f.Sha256)).ToLookup(f => f.Sha256!.ToLowerInvariant(), StringComparer.Ordinal);
var unhashed = local.Where(f => string.IsNullOrEmpty(f.Sha256) && Readable(f)).GroupBy(f => f.Size).ToDictionary(g => g.Key, g => g.Count());
var count = 0;
foreach (var frame in manifest.Frames.Where(f => f.WantsProxy && f.Sha256.Length > 0))
{
var sha = frame.Sha256.ToLowerInvariant();
if (hashed.Contains(sha))
{
if (hashed[sha].Any(Readable)) count++;
}
else if (unhashed.TryGetValue(frame.Size, out var left) && left > 0)
{
unhashed[frame.Size] = left - 1;
count++;
}
}
return count;
bool Readable(Frame frame) => !ArchiveImages.NeedsProxy(decoder, frame.Format);
}
/// <summary>
/// Whether <paramref name="local"/> holds originals a server cannot decode (it asks for their proxies, BRIEF §2.3,
/// §4.2: managed decoders only) that this PC's <paramref name="decoder"/> reads, so it can make those proxies.
/// </summary>
public static bool MakesProxiesFor(IEnumerable<Frame> local, ImageDecoder decoder) =>
local.Select(f => f.Format).Distinct().Any(format => ArchiveImages.ServerNeedsProxy(format) && !ArchiveImages.NeedsProxy(decoder, format));
internal static string Blank(string? text) => text?.Trim() ?? string.Empty;
private static JsonNode? Parse(string json)