Identify bulk-added episodes already in playlists#4027
Conversation
When adding multiple episodes to a playlist, pre-select playlists that already contain all of the selected episodes. Made-with: Cursor
bjtitus
left a comment
There was a problem hiding this comment.
This worked well for me in testing. Performance could be improved by iterating each episode and fetching playlists IDs, then using Set intersection but in practice I didn't notice it on any device I tried.
It was about a 6x speed improvement:
improvement.patch
This could be fixed up with some of our other performance improvements.
| // For bulk episodes, find playlists that contain ALL selected episodes | ||
| var playlistsContainingAllEpisodes: Set<String> = [] | ||
| for playlist in manualPlaylists { | ||
| let allEpisodesInPlaylist = episodes.allSatisfy { episode in | ||
| dataManager.manualPlaylistUUIDs(for: episode.uuid).contains(playlist.uuid) | ||
| } | ||
| if allEpisodesInPlaylist { | ||
| playlistsContainingAllEpisodes.insert(playlist.uuid) | ||
| } | ||
| } | ||
| initialSelectedPlaylists = playlistsContainingAllEpisodes |
There was a problem hiding this comment.
This could be sped up by iterating over and storing the playlist UUIDs in a Set and intersecting the sets. The more playlists you have the more this matters and in my testing it took quite a few (many dozens + hundreds of episodes) to notice any difference. We could fix this up later or now
| // For bulk episodes, find playlists that contain ALL selected episodes | |
| var playlistsContainingAllEpisodes: Set<String> = [] | |
| for playlist in manualPlaylists { | |
| let allEpisodesInPlaylist = episodes.allSatisfy { episode in | |
| dataManager.manualPlaylistUUIDs(for: episode.uuid).contains(playlist.uuid) | |
| } | |
| if allEpisodesInPlaylist { | |
| playlistsContainingAllEpisodes.insert(playlist.uuid) | |
| } | |
| } | |
| initialSelectedPlaylists = playlistsContainingAllEpisodes | |
| // For bulk episodes, find playlists that contain ALL selected episodes | |
| let playlistSets = episodes.map { episode in | |
| Set(dataManager.manualPlaylistUUIDs(for: episode.uuid)) | |
| } | |
| initialSelectedPlaylists = playlistSets.dropFirst().reduce(playlistSets.first ?? []) { accumulated, uuids in | |
| accumulated.intersection(uuids) | |
| } |
There was a problem hiding this comment.
Great suggestion. Lets do this for next release. Can you please create a ticket for it?
There was a problem hiding this comment.
I created an implementation on the find playlists containing episode using a direct SQL query here: #4026
I believe that approach could be more efficient when there is a lot of playlist and episodes to check.
When adding multiple episodes to a playlist, pre-select playlists that already contain all of the selected episodes.
Made-with: Claude Code
Fixes PCIOS-546
To test
Expected: The playlist containing all episodes should have its checkbox pre-selected
Checklist
CHANGELOG.mdif necessary.