Simplify store: replace pair mappings with explicit groups #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The current store models duplicate relationships as a flat list of track-to-track pairs (a graph of edges). Groups are only ever reconstructed at query time by computing the transitive closure of those edges. This produces several complexities:
group_undecideddoes graph traversal in application code to reassemble groups from pairs.decided_groups_with_rating_mismatchjoin across multiple tables and re-derive group membership.excludedflag on pairs (fromsplit_track) is a workaround for pairs that are edges in the graph but should not be treated as same-group.Proposed change
Replace the pairs/decisions tables with an explicit groups model:
Key behaviours that change:
find: instead of upserting pairs, upsert group members directly. Two tracks that match go into the same group (merge if they were in separate groups).evaluate/review: setcanonical_idon the group.sync: upserting a track that already belongs to a group leaves the group intact; removing a track that is the canonical reopens the group (setscanonical_id = NULL).split_track: remove a member from a group (and optionally form a new singleton group).export: readgroup_members WHERE group_id IN (SELECT id FROM groups WHERE canonical_id IS NOT NULL) AND track_id != canonical_id.Queries become direct SELECTs rather than in-memory graph traversal.
Migration
Since the user's collection is already marked, a SQLite migration must be provided:
excludedanddecidedflags).group_undecided).groups+group_members.Tests
decided_duplicate_ids()returns the same IDs as before.undecided_pairs()(or equivalent group query) returns the same groups as before.decided_groups_with_rating_mismatch()returns the same result.sync → find → evaluatecycle, snapshot the store state, run the migration, assert the snapshot is identical.