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:
9 files changed
+198
-18
No files matched your search
@@ -1,5 +1,8 @@
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Protocol;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Data.Tests.Sync;
|
||||
@@ -63,6 +66,38 @@ public sealed class SyncRulesTests
|
||||
Assert.Equal((1, 0), SyncRules.CompareOriginals([null, null], ["bb"]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProxiesTheServerAsksForAreCountedForOriginalsThisPcReads()
|
||||
{
|
||||
var heif = new ImageDecoder([new NativeHeif()]);
|
||||
List<Frame> local =
|
||||
[
|
||||
Original("aa", 100, ImageFileFormat.Heif),
|
||||
Original(null, 200, ImageFileFormat.Heif),
|
||||
Original(null, 300, ImageFileFormat.Heif),
|
||||
Original("dd", 400, ImageFileFormat.Avif),
|
||||
];
|
||||
var manifest = new SequenceManifest(Guid.CreateVersion7(), 1, 1, null, [],
|
||||
[
|
||||
Wanted("AA", 100, "2026-10-01_0001.heic"),
|
||||
// Not hashed here: matched by size, whatever name the server gave its copy.
|
||||
Wanted("bb", 200, "2026-10-01_0002.heic"),
|
||||
Wanted("cc", 999, "IMG_0003.HEIC"),
|
||||
// The server has no hash of it yet: nothing tells which original it is.
|
||||
Wanted(string.Empty, 300, "IMG_0004.HEIC"),
|
||||
// This PC cannot decode AVIF.
|
||||
Wanted("dd", 400, "IMG_0005.AVIF"),
|
||||
Wanted("ee", 200, "IMG_0006.HEIC") with { WantsProxy = false },
|
||||
], [], new ProxySpec(1920, 90));
|
||||
|
||||
Assert.Equal(2, SyncRules.ProxiesToSend(manifest, local, heif));
|
||||
Assert.Equal(0, SyncRules.ProxiesToSend(manifest, local, DecoderFactory.CreateServer()));
|
||||
|
||||
Assert.True(SyncRules.MakesProxiesFor(local, heif), "HEIF the server cannot decode and this PC can");
|
||||
Assert.False(SyncRules.MakesProxiesFor(local, DecoderFactory.CreateServer()), "a PC that reads no more than the server");
|
||||
Assert.False(SyncRules.MakesProxiesFor([Original("aa", 100, ImageFileFormat.Jpeg)], heif), "the server decodes JPEG itself");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsAreComparedAsProjectsNotAsText()
|
||||
{
|
||||
@@ -92,4 +127,29 @@ public sealed class SyncRulesTests
|
||||
Assert.True(mine.SameMetadata(mine with { Tags = ["HARBOUR", "sunset"], Notes = "mine " }), "tags ignore case and order, blanks are trimmed");
|
||||
Assert.Empty(SyncRules.Differences(mine, mine with { Tags = ["harbour", "SUNSET"] }));
|
||||
}
|
||||
|
||||
private static Frame Original(string? sha, long size, ImageFileFormat format) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = Local.Id,
|
||||
Index = (int)(size / 100),
|
||||
RelativePath = $"2026/a/{size}",
|
||||
FileName = $"{size}",
|
||||
Size = size,
|
||||
Sha256 = sha,
|
||||
Format = format,
|
||||
};
|
||||
|
||||
private static ManifestFrame Wanted(string sha, long size, string name) =>
|
||||
new(Guid.CreateVersion7(), (int)(size / 100), name, size, sha, HasProxy: false, HasThumb: true, WantsProxy: true);
|
||||
|
||||
/// <summary>A provider that decodes HEIF natively (WIC with the HEIF extension on a desktop).</summary>
|
||||
private sealed class NativeHeif : IImageDecoderProvider
|
||||
{
|
||||
public string Name => "native-heif";
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format) => format == ImageFileFormat.Heif ? DecodeTier.Native : null;
|
||||
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default) => null;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,59 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Holy grail")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadOfAnUnverifiedCopySendsTheProxiesTheServerAsksFor()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
// An adopted folder (never verified, so its frames have no hash here) whose originals the server already holds
|
||||
// under the names it gave them, and cannot decode (HEIF, BRIEF §2.3).
|
||||
var folder = Path.Combine(f.Archive.Paths.Root, "Adopted");
|
||||
Directory.CreateDirectory(folder);
|
||||
for (var i = 0; i < 3; i++) await File.WriteAllBytesAsync(Path.Combine(folder, $"DSC_{i + 1:0000}.JPG"), photos[i], f.Ct);
|
||||
await f.Archive.ScanAsync();
|
||||
var local = Assert.Contains((await f.Db.Sequences.ListAsync(new Titano.Data.Repositories.SequenceQuery(), f.Ct)).Items, s => s.Folder == "Adopted");
|
||||
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).All(fr => fr.Sha256 is null), "adopted frames are unhashed");
|
||||
var remote = f.Remote.Add("Adopted", photos);
|
||||
remote.Undecodable = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var ahead = await f.EntryAsync(local.DisplayTitle);
|
||||
Assert.Equal((SyncStatus.LocalAhead, 3), (ahead.Status, ahead.Link!.MissingRemote));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
var done = await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.True(f.Remote.SentProxies.Keys.ToHashSet().SetEquals(remote.Frames.Select(r => r.Id)), "a proxy of every frame");
|
||||
Assert.Contains(Loc.L("Archive.Log.ProxiesSent", 3, 0), done.LogTail);
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync(local.DisplayTitle)).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProxiesSentFromElsewhereAreNoLongerCountedHere()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Holy grail", photos);
|
||||
var remote = f.Remote.Add("Holy grail", photos);
|
||||
remote.Undecodable = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(2, (await f.EntryAsync("Holy grail")).Link!.MissingRemote);
|
||||
var calls = f.Remote.ManifestCalls;
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(calls, f.Remote.ManifestCalls);
|
||||
|
||||
// A render node sends them after a job: the server's frame counters stand still, its sequence changes.
|
||||
foreach (var frame in remote.Frames) f.Remote.SentProxies[frame.Id] = frame.Proxy;
|
||||
remote.UpdatedAt = remote.UpdatedAt.AddSeconds(1);
|
||||
await f.RefreshAsync();
|
||||
|
||||
var entry = await f.EntryAsync("Holy grail");
|
||||
Assert.Equal((SyncStatus.InSync, 0), (entry.Status, entry.Link!.MissingRemote));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AResumedUploadSendsOnlyWhatTheServerLacks()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user