fix(sync): let a photo's hash decide which frames hold it
Telling copies of a photo apart counted a frame not hashed yet with the same size and capture time as a hashed photo's copy, although it may be another photo (a RAW of constant size in a burst without sub-second times). Positions then shifted between copies: an exclusion waited forever as a pending frame, or landed on the other photo. A hashed photo is now the frames holding its hash; size and capture time count only when no frame holds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+45
-11
No files matched your search
@@ -84,19 +84,20 @@ public sealed class FramePhotos
|
||||
/// </summary>
|
||||
public int Occurrence(int index) => this[index] is { } photo ? Math.Max(Holding(photo).BinarySearch(index), 0) : 0;
|
||||
|
||||
/// <summary>The indices of the frames holding <paramref name="photo"/>, ascending.</summary>
|
||||
/// <summary>
|
||||
/// The indices of the frames holding <paramref name="photo"/>, ascending. A hashed photo is the frames with its SHA-256
|
||||
/// when there are any: a frame not hashed yet with the same size and capture time may be another photo (a RAW of
|
||||
/// constant size in a burst without sub-second times), so it counts only when no frame has the hash.
|
||||
/// </summary>
|
||||
private List<int> Holding(FramePhoto photo)
|
||||
{
|
||||
if (photo.IsHashed && _bySha.TryGetValue(photo.Sha256!.ToLowerInvariant(), out var hashed)) return hashed;
|
||||
var holding = new List<int>(1);
|
||||
if (photo.IsHashed && _bySha.TryGetValue(photo.Sha256!.ToLowerInvariant(), out var hashed)) holding.AddRange(hashed);
|
||||
if (photo.CapturedAt is not { } time || !_bySizeAndTime.TryGetValue((photo.Size, FramePhoto.Millisecond(time)), out var candidates)) return holding;
|
||||
// Frames not hashed on one side match by size and capture time; a hashed photo's hashed frames are listed already.
|
||||
foreach (var index in candidates)
|
||||
{
|
||||
var frame = _byIndex[index]!;
|
||||
if (!(photo.IsHashed && frame.IsHashed) && frame.Matches(photo)) holding.Add(index);
|
||||
if (_byIndex[index]!.Matches(photo)) holding.Add(index);
|
||||
}
|
||||
if (holding.Count > 1) holding.Sort();
|
||||
return holding;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user