SubmarinerApp / Submariner

A Subsonic client for macOS
https://submarinerapp.com
BSD 3-Clause "New" or "Revised" License
122 stars 3 forks source link

Initial attempt at changing the playlist schema #207

Closed NattyNarwhal closed 3 weeks ago

NattyNarwhal commented 3 weeks ago

Initially, playlists were handled by a one-to-many relationship of playlist to track, with an index attribute for sorting. However, this had the problem of only allowing for one track instance per playlist, and a single index for sorting. This was covered up by fetching Subsonic playlists, but was still an issue in most cases, especially local playlists.

This attempts to fix it by changing it from a relation to an array; specifically an array of URLs containing the Core Data object ID URIs. This allows for having multiple entries, and makes working with it more idiomatic as opposed to the NSSet based relation approach. However, it has some trade-offs:

This does the initial conversions from NSSet to [SBTrack], as well as refactors in SBPlaylist, the parsing operation, and the playlist view controller. It also contains our first heavyweight migration, including the magic words in the Core Data mapping DSL, such as:

FUNCTION($entityPolicy, "entriesFromTracks:" , $source.tracks)

I had considered using a traditional SQL approach, where you have a many to many entity that would effectively provide a {playlist, track, order} tuple. However, I decided against it because it would create a lot of junk objects and complicate things. If it turns out to be the right decision, we can always make another migration from the URI array towards that.

Fixes GH-192.

NattyNarwhal commented 3 weeks ago

I asked people I trust around Core Data and they think it's OK; if not, we can again, do a migration to a traditional many to many approach later. Merging the Big Change.