Owner review 6 asks Chronos to recognise the same time-lapse held under different ids on the server and on this PC, compare the copies, and keep them apart or integrate and sync them. This lays the shared foundation the later parcels build on, without any UI or detection yet. - Migration 0012 adds found_copies (local-server and local-local pairs with evidence, scores, answer, policy and the 404 record) and copy_probes; every existing link with a local sequence becomes a Linked pair, so a server deletion and the per-link policy have a place. - FoundCopyStore keeps the pairs: upserts that never touch the answer, a compare-and-set of the state with an Integrating backstop (a failed or cancelled job reads as the previous state), link promotion and demotion, the once-per-refresh 404 count, the merge's links stage (session keys, links reset, pairs moved, refused when both are linked on one server), the local overlap queries and the probes. SyncLinkStore.RekeyAsync moves pairs and probes with the links in the same transaction. - Contracts for detection, review, plans, the Integrate and MergeSequences jobs (kinds 25/26, High level, new detail steps) and the Upload all rule that keeps suspected, kept-apart, deleted, busy and server-born sequences here. - Wire: POST photos/lookup, uploads into a target (IntoTarget/Copied, trailing and optional), frames/delete on the client, capabilities photo-lookup and upload-into, cached per remote. - The trash plans and deletes accept the job that holds the sequence (its own hold is not Busy) and a frames version checked under the lease; a Background job never interrupts a running one. - Settings for linking, the photo policy and projects; the en and it keys of design section 9. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3.4 KiB
C#
78 lines
3.4 KiB
C#
using Chronos.Data.Sync;
|
|
|
|
namespace Chronos.Data.Copies;
|
|
|
|
/// <summary>Why Upload all local left a sequence out (owner review 6, Q8).</summary>
|
|
public enum UploadSkip
|
|
{
|
|
/// <summary>In a match nobody answered yet: it may be on the server already.</summary>
|
|
SuspectedCopy,
|
|
|
|
/// <summary>The user kept it apart from a match.</summary>
|
|
KeptApart,
|
|
|
|
/// <summary>It lies in a server's originals archive: it came from a server.</summary>
|
|
ServerOriginals,
|
|
|
|
/// <summary>The server deleted its copy (a 404 for the linked sequence).</summary>
|
|
DeletedOnServer,
|
|
|
|
/// <summary>An Integrate or Merge job holds it, or will.</summary>
|
|
Busy,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Which local-only sequences Upload all local sends (design §6.4, owner review 6, Q8): suspected copies, kept-apart ones,
|
|
/// those the server deleted, those an Integrate or Merge holds and those in any server's originals archive are skipped and
|
|
/// flagged, never uploaded as new server sequences. Pure.
|
|
/// </summary>
|
|
public static class UploadAllRule
|
|
{
|
|
/// <summary>
|
|
/// Splits <paramref name="localOnly"/> into the entries to upload and those skipped with the reason.
|
|
/// <paramref name="copies"/> are every pair of the index (any server, and local pairs); <paramref name="serverOriginalsArchives"/>
|
|
/// every known server's originals archive (the current one's too); <paramref name="busy"/> the targets of pending or
|
|
/// running Integrate and MergeSequences jobs. An entry without a local sequence is neither.
|
|
/// </summary>
|
|
public static (IReadOnlyList<SyncEntry> Upload, IReadOnlyList<(SyncEntry Entry, UploadSkip Why)> Skipped) Select(
|
|
IEnumerable<SyncEntry> localOnly, IReadOnlyCollection<FoundCopy> copies, IReadOnlySet<Guid> serverOriginalsArchives,
|
|
IReadOnlySet<Guid> busy)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(localOnly);
|
|
ArgumentNullException.ThrowIfNull(copies);
|
|
ArgumentNullException.ThrowIfNull(serverOriginalsArchives);
|
|
ArgumentNullException.ThrowIfNull(busy);
|
|
|
|
var bySequence = new Dictionary<Guid, List<FoundCopy>>();
|
|
foreach (var copy in copies)
|
|
{
|
|
Add(copy.LocalId, copy);
|
|
if (copy.OtherId is { } other) Add(other, copy);
|
|
}
|
|
|
|
var upload = new List<SyncEntry>();
|
|
var skipped = new List<(SyncEntry, UploadSkip)>();
|
|
foreach (var entry in localOnly)
|
|
{
|
|
if (entry.Local is not { } local) continue;
|
|
var pairs = bySequence.GetValueOrDefault(local.Id) ?? [];
|
|
UploadSkip? why =
|
|
busy.Contains(local.Id) || pairs.Any(p => p.State == CopyState.Integrating) ? UploadSkip.Busy
|
|
: pairs.Any(p => p.Kind == CopyKind.LocalServer && p.RemoteGoneHits >= 1) ? UploadSkip.DeletedOnServer
|
|
: pairs.Any(p => p.State == CopyState.KeptApart) ? UploadSkip.KeptApart
|
|
: pairs.Any(p => p.State == CopyState.Candidate) ? UploadSkip.SuspectedCopy
|
|
: serverOriginalsArchives.Contains(local.ArchiveId) ? UploadSkip.ServerOriginals
|
|
: null;
|
|
if (why is { } reason) skipped.Add((entry, reason));
|
|
else upload.Add(entry);
|
|
}
|
|
return (upload, skipped);
|
|
|
|
void Add(Guid id, FoundCopy copy)
|
|
{
|
|
if (!bySequence.TryGetValue(id, out var list)) bySequence[id] = list = [];
|
|
list.Add(copy);
|
|
}
|
|
}
|
|
}
|