[gnome-music/wip/jfelder/player-discovery: 4/4] player: Do not reset validation if the playlist is unchanged



commit e24017a5f0a86da21c460f668de092818d62525d
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Feb 13 12:10:40 2019 +0100

    player: Do not reset validation if the playlist is unchanged
    
    _validation_indexes keeps track of the songs being validated. Every
    time a new playlist is loaded or a new song from the same playlist is
    loaded by clicking on it, this list is reset. In the latter case, it
    works fine in most of the cases because the discovery mechanism (which
    is asynchronous) is fast enough to end before the user can click on an
    other song. Indeed, the list is already empty when it is reset.
    However, on a slow configuration, it is possible to select an other
    song before the end of the discovery mechanism. So, the validation
    list is reset even if a discovery is running. This results in a crash
    as reported by #252.
    
    The solution is to not reset _validation_indexes if the playlist is
    unchanged. Also, introduce a new ValidationStatus (IN_PROGRESS) when a
    song is being validated. This prevents to queue multiple times the
    same song on a slow configuration.
    
    closes: #252

 gnomemusic/player.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 6a077092..67214a83 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -59,8 +59,9 @@ class RepeatMode(IntEnum):
 class ValidationStatus(IntEnum):
     """Enum for song validation"""
     PENDING = 0
-    FAILED = 1
-    SUCCEEDED = 2
+    IN_PROGRESS = 1
+    FAILED = 2
+    SUCCEEDED = 3
 
 
 class PlayerField(IntEnum):
@@ -127,7 +128,6 @@ class PlayerPlaylist(GObject.GObject):
         """
         path = model.get_path(model_iter)
         self._current_index = int(path.to_string())
-        self._validation_indexes = defaultdict(list)
 
         # Playlist is the same. Check that the requested song is valid.
         # If not, try to get the next valid one
@@ -140,6 +140,7 @@ class PlayerPlaylist(GObject.GObject):
                 self._validate_next_song()
             return False
 
+        self._validation_indexes = defaultdict(list)
         self._type = playlist_type
         self._id = playlist_id
 
@@ -283,8 +284,9 @@ class PlayerPlaylist(GObject.GObject):
     @log
     def _validate_song(self, index):
         item = self._songs[index]
-        # Song has already been processed, nothing to do.
-        if item[PlayerField.VALIDATION] != ValidationStatus.PENDING:
+        # Song is being processed or has already been processed.
+        # Nothing to do.
+        if item[PlayerField.VALIDATION] > ValidationStatus.PENDING:
             return
 
         song = item[PlayerField.SONG]
@@ -297,6 +299,7 @@ class PlayerPlaylist(GObject.GObject):
                 "Skipping validation of {} as not a local file".format(url))
             return
 
+        item[PlayerField.VALIDATION] = ValidationStatus.IN_PROGRESS
         self._validation_indexes[url].append(index)
         self._discoverer.discover_uri_async(url)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]