The review of the found-copies work showed pairs that could stick, jobs that could act on a pair the user had answered otherwise, and detection gaps: - forgetting a link on an address-keyed server deletes the pair and Candidate rows of that remote and resets the probe, so the sequence is found again when it is back; a Linked/Integrated row with no link is asked again - 404s count only on id-keyed servers, at most once per recheck interval - probes store the server's newest update time (copy_probes.server_newest, migration 0012) instead of comparing with this PC's clock; the lookup sample carries hashed photos by size and capture time too, for servers that have not hashed their copy - the older-server gate no longer re-compares unchanged manifests - a failed Integrate keeps its job id so a retry resumes only an untouched pair; cancel and stale plans release the pair (ReleaseAsync) - automatic photo transfers never create or retarget a sequence - a first upload files photos the server holds elsewhere into the new sequence - Unlink re-compares before keeping apart; Trash here names only true last copies; Drop... trashes one version on both sides after re-checking the other - a merge keeping the pair's other sequence swaps the dialog's columns and re-keys Different choices; Upload all reads every pair Each fix has a regression test where it makes sense. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
4.6 KiB
SQL
76 lines
4.6 KiB
SQL
-- Found copies (owner review 6, #73): two copies of one time-lapse whose ids differ, a local sequence and a sequence of a
|
|
-- server (kind 0) or two local sequences of this index (kind 1), with the evidence, the scores of the last comparison, the
|
|
-- user's answer and, once integrated, the pair's policy. A pair is never two links: sync_links stays the 1:1 per server
|
|
-- record a sync compares; every link has a row here too (evidence 0, state 2), so a server deletion and the per-link policy
|
|
-- have a place. Scores are counts and per-mille ratios of the last exact comparison, at the frames versions it read. The
|
|
-- answered_* columns keep what a "Keep apart" was given, so only a large later change asks again. remote_gone_* record a
|
|
-- server's 404 for the remote side (two answers on two refreshes before the pair reads "deleted on server"). Local columns
|
|
-- cascade: a sequence deleted into the trash (or removed by Rebuild, Orphans or Reidentify) takes its pairs along; the
|
|
-- next detection finds such a pair again as a candidate (DECISIONS). Mirrors postgres/0012_found_copies.sql.
|
|
|
|
CREATE TABLE found_copies (
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
kind INTEGER NOT NULL,
|
|
local_id TEXT NOT NULL REFERENCES sequences (id) ON DELETE CASCADE,
|
|
server TEXT,
|
|
remote_id TEXT,
|
|
other_id TEXT REFERENCES sequences (id) ON DELETE CASCADE,
|
|
evidence INTEGER NOT NULL,
|
|
state INTEGER NOT NULL DEFAULT 0,
|
|
shared INTEGER NOT NULL DEFAULT 0,
|
|
shared_unhashed INTEGER NOT NULL DEFAULT 0,
|
|
shared_removed INTEGER NOT NULL DEFAULT 0,
|
|
only_here INTEGER NOT NULL DEFAULT 0,
|
|
only_there INTEGER NOT NULL DEFAULT 0,
|
|
differs INTEGER NOT NULL DEFAULT 0,
|
|
deleted_here INTEGER NOT NULL DEFAULT 0,
|
|
deleted_there INTEGER NOT NULL DEFAULT 0,
|
|
versions INTEGER NOT NULL DEFAULT 0,
|
|
local_photos INTEGER NOT NULL DEFAULT 0,
|
|
other_photos INTEGER NOT NULL DEFAULT 0,
|
|
containment INTEGER NOT NULL DEFAULT 0,
|
|
overlap INTEGER NOT NULL DEFAULT 0,
|
|
hints INTEGER NOT NULL DEFAULT 0,
|
|
local_frames_version INTEGER NOT NULL DEFAULT 0,
|
|
other_frames_version INTEGER NOT NULL DEFAULT 0,
|
|
fingerprint TEXT NOT NULL,
|
|
answered_fingerprint TEXT,
|
|
answered_shared INTEGER,
|
|
auto_photos INTEGER NOT NULL DEFAULT 0,
|
|
job_id TEXT,
|
|
previous_state INTEGER,
|
|
remote_gone_at TEXT,
|
|
remote_gone_hits INTEGER NOT NULL DEFAULT 0,
|
|
found_at TEXT NOT NULL,
|
|
updated_at TEXT NOT NULL,
|
|
answered_at TEXT,
|
|
CHECK ((kind = 0 AND server IS NOT NULL AND remote_id IS NOT NULL AND other_id IS NULL)
|
|
OR (kind = 1 AND server IS NULL AND remote_id IS NULL AND other_id IS NOT NULL AND other_id <> local_id))
|
|
);
|
|
CREATE UNIQUE INDEX ux_found_copies_remote ON found_copies (local_id, server, remote_id) WHERE kind = 0;
|
|
CREATE UNIQUE INDEX ux_found_copies_local ON found_copies (local_id, other_id) WHERE kind = 1;
|
|
CREATE INDEX ix_found_copies_server ON found_copies (server, remote_id);
|
|
CREATE INDEX ix_found_copies_other ON found_copies (other_id);
|
|
CREATE INDEX ix_found_copies_state ON found_copies (state);
|
|
|
|
-- What detection last sent or compared of each local sequence, per scope (a server key, or '' for this PC's archives):
|
|
-- a sequence whose frames version and hashed count are unchanged is not probed again.
|
|
CREATE TABLE copy_probes (
|
|
sequence_id TEXT NOT NULL REFERENCES sequences (id) ON DELETE CASCADE,
|
|
scope TEXT NOT NULL,
|
|
frames_version INTEGER NOT NULL,
|
|
hashed INTEGER NOT NULL,
|
|
probed_at TEXT NOT NULL,
|
|
server_newest TEXT,
|
|
PRIMARY KEY (sequence_id, scope)
|
|
);
|
|
|
|
-- Every existing link is a linked pair (no score yet: the next comparison fills it). Ids are random v4 UUIDs.
|
|
INSERT INTO found_copies (id, kind, local_id, server, remote_id, evidence, state, fingerprint, found_at, updated_at)
|
|
SELECT lower(substr(h, 1, 8) || '-' || substr(h, 9, 4) || '-4' || substr(h, 14, 3) || '-'
|
|
|| substr('89ab', 1 + (abs(random()) % 4), 1) || substr(h, 18, 3) || '-' || substr(h, 21, 12)),
|
|
0, local_id, server, remote_id, 0, 2, 'link', ts, ts
|
|
FROM (SELECT hex(randomblob(16)) AS h, local_id, server, remote_id,
|
|
strftime('%Y-%m-%dT%H:%M:%f', 'now') || '000Z' AS ts
|
|
FROM sync_links WHERE local_id IS NOT NULL);
|