[gnome-music/wip/gbsneto/flowbox: 2/7] playlists: asynchronously clear static playlists



commit eeff466840c279f0dd4193fb9d26b87c73683a51
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Aug 10 22:29:09 2016 -0300

    playlists: asynchronously clear static playlists
    
    In my machine, clearing the static playlists can consume
    up to 3 minutes. Since this is done synchronously, it blocks
    the UI and renders GNOME Music unusable.
    
    Fix that by clearing the statis playlists asynchronously
    and not blocking the UI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769721

 gnomemusic/playlists.py |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index a7aaaf8..120d07b 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -136,6 +136,10 @@ class Playlists(GObject.GObject):
                 # create the playlist
                 playlist.ID = self.create_playlist_and_return_id(playlist.TITLE, playlist.TAG_TEXT)
 
+            # Clear the playlist
+            self.clear_static_playlist(playlist, on_clear_playlist_ready)
+
+        def on_clear_playlist_ready(conn, res, playlist):
             self.update_static_playlist(playlist)
 
         for playlist in playlists:
@@ -144,9 +148,11 @@ class Playlists(GObject.GObject):
                 callback, playlist)
 
     @log
-    def clear_playlist_with_id(self, playlist_id):
-        query = Query.clear_playlist_with_id(playlist_id)
-        self.tracker.update(query, GLib.PRIORITY_LOW, None)
+    def clear_static_playlist(self, playlist, callback):
+        """Asyncronously clear the given static playlist."""
+        query = Query.clear_playlist_with_id(playlist.ID)
+        self.tracker.update_async(query, GLib.PRIORITY_LOW, None,
+                                  callback, playlist)
 
     @log
     def update_playcount(self, song_url):
@@ -162,13 +168,16 @@ class Playlists(GObject.GObject):
     @log
     def update_static_playlist(self, playlist):
         """Given a static playlist (subclass of StaticPlaylists), updates according to its query."""
-        # Clear the playlist
-        self.clear_playlist_with_id(playlist.ID)
 
+        # Asyncronously get a list of matching songs
+        self.tracker.query_async(playlist.QUERY, None,
+                                 self._on_static_playlist_updated, playlist)
+
+    @log
+    def _on_static_playlist_updated(self, conn, res, playlist):
         final_query = ''
 
-        # Get a list of matching songs
-        cursor = self.tracker.query(playlist.QUERY, None)
+        cursor = conn.query_finish(res)
         if not cursor:
             return
 


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