Commit graph sonda/internal/duplicates
Author SHA1 Message Date
tgiachi
ce109a14a3 fix(duplicates): move the playlist items of a removed copy to the one that stays
playlist_items.track_id is ON DELETE CASCADE (added by the playlists work on main), so deleting a
duplicate would have taken the song out of every user's playlists, as it would have done with the
listens. RemoveCopy now repoints the items first, in the same transaction.

Also merges main (playlists) into the branch.
2026-11-12 17:01:36 +01:00
tgiachi
05f4e33470 fix(duplicates): finish updating the index even if the client leaves after the file is deleted
Found reviewing the branch: a request cancelled between deleting the file and updating the index left a track whose file does not exist. The index step no longer depends on the request's context. Test first: it cancels the request at exactly that moment.
2026-11-12 16:52:38 +01:00
tgiachi
d3e3bde2e4 feat(duplicates): find the copies, fingerprint their files and remove the extra ones
Groups come from the index. The check job reads the files of the groups and keeps their SHA-256, skipping a file that changed since the scan. Clean refuses unless deleting is on and no scan runs, works out again that the tracks are copies of one song, checks every file is still what the scan saw (so the last copy is never removed, and a link or a path that leaves the library is refused) before removing any, removes each file through an os.Root, then takes its track out of the index and moves its listens. Tested with real files, including the refusals; three of the safety rules were broken on purpose to see the tests fail.
2026-11-12 16:40:43 +01:00
tgiachi
65edfc4918 feat(storage): candidates for duplicates, file fingerprints and removing a copy from the index
Candidates are the playable files whose title another file shares. A fingerprint is kept only for the file that was read (same size and date), and a scan that finds the file changed forgets it. Removing a copy moves its listens to the track that stays, because they would be deleted with the track, then removes the track with its file, credits and genres. Tested on SQLite and PostgreSQL.
2026-11-12 16:37:15 +01:00
tgiachi
7e1e63bdd2 feat(duplicates): group the copies of a song and propose the one to keep
The same song is the same set of main artists, the same title and durations within 3 seconds, every pair within it; a file with no duration or no artist never matches. A group says whether its files were all read and are byte for byte the same. The copy to keep is the lossless one, then the higher bitrate, then the bigger file, then the oldest, whatever the order of the input.
2026-11-12 16:34:12 +01:00