[gnome-music/wip/mschraal/set-player-model-cleanups-3-34: 3/4] coremodel: Compress items-changed signal



commit 95ad5a2ef023e55bb5491ccadcff194589469d2b
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Nov 3 13:21:10 2019 +0100

    coremodel: Compress items-changed signal
    
    In set_player_model the player model is set to listen to the changes on
    the base model(s) of the currently active playlist. When changing
    playlists this results in remove_all call and adding all new song items
    one by one. This is very chatty signal-wise for 'items-changed'
    listeners on the listmodel. It also signals that the player model is
    empty for a short while, which has some unforseen side-effects.
    
    Instead, collect all the changes and splice them in one go.
    
    Related: #332, #335

 gnomemusic/coremodel.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index d6ea0283..dc549722 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -268,7 +268,7 @@ class CoreModel(GObject.GObject):
                 and self.props.active_playlist is not None):
             self.props.active_playlist = None
 
-        self._playlist_model.remove_all()
+        songs_added = []
 
         if playlist_type == PlayerPlaylist.Type.ALBUM:
             proxy_model = Gio.ListStore.new(Gio.ListModel)
@@ -285,7 +285,7 @@ class CoreModel(GObject.GObject):
                     model_song.props.media, self._coreselection,
                     self.props.grilo)
 
-                self._playlist_model.append(song)
+                songs_added.append(song)
                 song.bind_property(
                     "state", model_song, "state",
                     GObject.BindingFlags.SYNC_CREATE)
@@ -310,7 +310,7 @@ class CoreModel(GObject.GObject):
                     model_song.props.media, self._coreselection,
                     self.props.grilo)
 
-                self._playlist_model.append(song)
+                songs_added.append(song)
                 song.bind_property(
                     "state", model_song, "state",
                     GObject.BindingFlags.SYNC_CREATE)
@@ -323,7 +323,7 @@ class CoreModel(GObject.GObject):
             self._current_playlist_model = self._songliststore.props.model
 
             for song in self._songliststore.props.model:
-                self._playlist_model.append(song)
+                songs_added.append(song)
 
                 if song.props.state == SongWidget.State.PLAYING:
                     song.props.state = SongWidget.State.PLAYED
@@ -332,7 +332,7 @@ class CoreModel(GObject.GObject):
             self._current_playlist_model = self._song_search_flatten
 
             for song in self._song_search_flatten:
-                self._playlist_model.append(song)
+                songs_added.append(song)
 
         elif playlist_type == PlayerPlaylist.Type.PLAYLIST:
             self._current_playlist_model = model
@@ -342,7 +342,7 @@ class CoreModel(GObject.GObject):
                     model_song.props.media, self._coreselection,
                     self.props.grilo)
 
-                self._playlist_model.append(song)
+                songs_added.append(song)
 
                 song.bind_property(
                     "state", model_song, "state",
@@ -352,6 +352,9 @@ class CoreModel(GObject.GObject):
                     GObject.BindingFlags.BIDIRECTIONAL
                     | GObject.BindingFlags.SYNC_CREATE)
 
+        self._playlist_model.splice(
+            0, self._playlist_model.get_n_items(), songs_added)
+
         if self._current_playlist_model is not None:
             self._player_signal_id = self._current_playlist_model.connect(
                 "items-changed", _on_items_changed)


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