fix(sync): translate positions only against the frames they name
Positions crossing copies could still land on other photos in three windows: - A push translated a row snapshot's settings against local frames listed later, after a manifest round trip: an import of earlier photos meanwhile moved the row's positions, and the server stored shifted exclusions, hero and keyframes. SyncPositions now reads this copy's row with its frames as one state (frames listed between two reads of the row at the same frames version) and translates that row's settings, at the settings version being pushed. The conflict comparison and ApplyLocallyAsync compare against that same row. When the copy was edited since, or its frames keep changing, nothing is sent or applied and the next comparison translates again (Keep mine reports a changed conflict; PushAll sends an edit saved meanwhile). - The manifest read the sequence row, then paged its frames: an upload committed in between paired settings of one frames version with frames of the next. The server now lists them again while the frames version moved during the listing, then inside a transaction holding the row (on SQLite, on that transaction's connection, so no second pooled connection waits behind the write lock). The client also refuses to translate against a manifest whose frames are not each listed once at 0..n-1. - Server capture times were fetched only when something was unhashed, so the same parked photo was written with or without capturedAt. They are now fetched whenever the two frame lists differ; an equal project then compares equal, and an entry can be placed on a photo that arrives unhashed. CompareOriginals counted unhashed server frames one-to-one against this PC's photos, so two copies of one photo in a folder the server adopted left Download on offer forever while the download fetched nothing. A photo on either side is now there when any photo of the other side matches it, as downloads and uploads find them. Paged frame listings keep each frame once (an insertion between pages lists one again). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
12 files changed
+322
-95
No files matched your search
@@ -1,7 +1,9 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using Titano.Data;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Api;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests.Api;
|
||||
@@ -114,6 +116,59 @@ public sealed class SequenceTests(TestContext context)
|
||||
Assert.Count(3, (await changed.ReadAsync(ProtocolJson.Default.SequenceManifest)).Frames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheManifestListsTheFramesOfOneFramesVersion()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
await FramesOfOneVersionAsync(server);
|
||||
}
|
||||
|
||||
/// <summary>The manifest's frames are read again while frames are committed, then under the row lock (also run on PostgreSQL).</summary>
|
||||
internal static async Task FramesOfOneVersionAsync(TestServer server)
|
||||
{
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 51), "a.CR3", sessionKey: "k");
|
||||
var db = server.Database;
|
||||
var id = first.SequenceId;
|
||||
var start = (await db.Sequences.GetAsync(id))!.FramesVersion;
|
||||
|
||||
// Frames are committed while the first listing is read: it is read again.
|
||||
var listings = new List<int>();
|
||||
var snapshot = await SequenceEndpoints.SnapshotAsync(db, id, async (_, sequence, ct) =>
|
||||
{
|
||||
listings.Add(sequence.FramesVersion);
|
||||
if (listings.Count == 1) await db.Sequences.RefreshStatsAsync(id, ct);
|
||||
return [];
|
||||
}, CancellationToken.None);
|
||||
Assert.SequenceEqual([start, start + 1], listings);
|
||||
Assert.Equal(start + 1, Assert.NotNull(snapshot).Sequence.FramesVersion);
|
||||
|
||||
// Commits keep landing: the last listing is read while none can.
|
||||
Task? waiting = null;
|
||||
listings.Clear();
|
||||
var locked = await SequenceEndpoints.SnapshotAsync(db, id, async (on, sequence, ct) =>
|
||||
{
|
||||
listings.Add(sequence.FramesVersion);
|
||||
if (listings.Count <= 3)
|
||||
{
|
||||
await db.Sequences.RefreshStatsAsync(id, ct);
|
||||
return [];
|
||||
}
|
||||
// Listed on the transaction that holds the row (on SQLite, the only connection that may while it writes).
|
||||
Assert.True(on is TitanoTransaction, "the frames are listed inside the locking transaction");
|
||||
Assert.Count(1, await on.Frames.ListBySequenceAsync(id, cancellationToken: ct));
|
||||
waiting = db.Sequences.RefreshStatsAsync(id, ct);
|
||||
await Task.WhenAny(waiting, Task.Delay(300, ct));
|
||||
Assert.False(waiting.IsCompleted, "a commit of frames waits until the frames are listed");
|
||||
return [];
|
||||
}, CancellationToken.None);
|
||||
await Assert.NotNull(waiting);
|
||||
Assert.SequenceEqual([start + 1, start + 2, start + 3, start + 4], listings);
|
||||
Assert.Equal(start + 4, Assert.NotNull(locked).Sequence.FramesVersion);
|
||||
Assert.Equal(start + 5, (await db.Sequences.GetAsync(id))!.FramesVersion);
|
||||
Assert.Null(await SequenceEndpoints.SnapshotAsync(db, Guid.NewGuid(), (_, _, _) => Task.FromResult(new List<ManifestFrame>()), CancellationToken.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ListingFiltersAndPagesWithACursor()
|
||||
{
|
||||
|
||||
@@ -54,6 +54,19 @@ public sealed class PostgresServerTests(TestContext context)
|
||||
Assert.Equal("ok", (await health.ReadAsync(ProtocolJson.Default.HealthStatus)).Checks["database"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheManifestListsTheFramesOfOneFramesVersionOnPostgres()
|
||||
{
|
||||
await using var schema = await Schema.CreateAsync(context);
|
||||
await using var server = await TestServer.StartAsync(context, o =>
|
||||
{
|
||||
o.Database = DatabaseKind.Postgres;
|
||||
o.DbConnectionString = schema.ConnectionString;
|
||||
});
|
||||
Assert.Equal(Dialect.Postgres, server.Database.Dialect);
|
||||
await Api.SequenceTests.FramesOfOneVersionAsync(server);
|
||||
}
|
||||
|
||||
/// <summary>A throw-away schema on the test server, selected through <c>Search Path</c>.</summary>
|
||||
private sealed class Schema : IAsyncDisposable
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user