SubmarinerApp / Submariner

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

Playlist duplicates for every right click, reload server action #132

Closed jboxman closed 1 year ago

jboxman commented 1 year ago

Hi,

I added a Navidrome server; I have a single playlist on that server. When I right click and select "Reload Server", the playlist is duplicated beneath the server:

Servers
  Test server
    test
    test
    test
    test

This happens when I click away, then back on the server name again as well.

NattyNarwhal commented 1 year ago

This one seems a little tricky to reproduce. I've noticed if after I quit (thus saving), and try this, it doesn't trigger reliably. But it does happen for me still...

NattyNarwhal commented 1 year ago

I noticed that the items that get repeated on reload are ones not already in Core Data on load.

i.e. I hit reload when some new playlists come in:

2023-05-27 19:09:48.687095-0300 Submariner[85391:7352968] Create new playlist : b22a7766-e88f-4e74-9b8c-99b33eae65fc: Nav
2023-05-27 19:09:49.880323-0300 Submariner[85391:7352968] Create new playlist : cec591ed-463a-43a4-a704-1f5b34233f94: _hey_Cool_Dudes_Support_Open_Source
2023-05-27 19:09:52.224946-0300 Submariner[85391:7352968] Create new playlist : cf5348c0-a21f-4537-a6f2-c2756c544afe: qwer
2023-05-27 19:09:55.318143-0300 Submariner[85391:7352968] Create new playlist : cab2cd1e-27c2-455c-a004-297f8662228c: yesyes
(lldb) 

After hitting reload again, the only dupes I see in the sidebar are those new playlists, and it matches the ones I see in console:

2023-05-27 19:09:48.687095-0300 Submariner[85391:7352968] Create new playlist : b22a7766-e88f-4e74-9b8c-99b33eae65fc: Nav
2023-05-27 19:09:49.880323-0300 Submariner[85391:7352968] Create new playlist : cec591ed-463a-43a4-a704-1f5b34233f94: _hey_Cool_Dudes_Support_Open_Source
2023-05-27 19:09:52.224946-0300 Submariner[85391:7352968] Create new playlist : cf5348c0-a21f-4537-a6f2-c2756c544afe: qwer
2023-05-27 19:09:55.318143-0300 Submariner[85391:7352968] Create new playlist : cab2cd1e-27c2-455c-a004-297f8662228c: yesyes
2023-05-27 19:10:15.889700-0300 Submariner[85391:7353175] Create new playlist : b22a7766-e88f-4e74-9b8c-99b33eae65fc: Nav
2023-05-27 19:10:16.607155-0300 Submariner[85391:7353175] Create new playlist : cec591ed-463a-43a4-a704-1f5b34233f94: _hey_Cool_Dudes_Support_Open_Source
2023-05-27 19:10:17.572737-0300 Submariner[85391:7353175] Create new playlist : cf5348c0-a21f-4537-a6f2-c2756c544afe: qwer
2023-05-27 19:10:18.613600-0300 Submariner[85391:7353175] Create new playlist : cab2cd1e-27c2-455c-a004-297f8662228c: yesyes

printf courtesy of diff:

diff --git a/Submariner/SBSubsonicParsingOperation.m b/Submariner/SBSubsonicParsingOperation.m
index 4cefe7c..b04e272 100644
--- a/Submariner/SBSubsonicParsingOperation.m
+++ b/Submariner/SBSubsonicParsingOperation.m
@@ -451,6 +451,7 @@ - (void)parseElementAlbum: (NSDictionary<NSString*,NSString*> *)attributeDict {

 - (void)parseElementPlaylist: (NSDictionary<NSString*,NSString*> *)attributeDict {
     if(requestType == SBSubsonicRequestGetPlaylists) {
+        NSLog(@"Getting playlist %@: %@", attributeDict[@"id"], [attributeDict valueForKey:@"name"]);

         // check if playlist exists
         SBPlaylist *newPlaylist = [self fetchPlaylistWithID:[attributeDict valueForKey:@"id"] orName:nil];
@@ -461,7 +462,7 @@ - (void)parseElementPlaylist: (NSDictionary<NSString*,NSString*> *)attributeDict
             // try with name
             newPlaylist = [self fetchPlaylistWithID:nil orName:[attributeDict valueForKey:@"name"]];
 #if DEBUG
-            NSLog(@"Create new playlist : %@", [attributeDict valueForKey:@"name"]);
+            NSLog(@"Create new playlist : %@: %@", attributeDict[@"id"], [attributeDict valueForKey:@"name"]);
 #endif
             if(!newPlaylist)
                 newPlaylist = [self createPlaylistWithAttribute:attributeDict];