[gnome-music] grltrackerwrapper: Optimize metadata queries
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] grltrackerwrapper: Optimize metadata queries
- Date: Mon, 31 Aug 2020 15:47:15 +0000 (UTC)
commit 6c899f01e9cded0a292b31613d040cb70ecedea9
Author: Peter Shkenev <santurysim gmail com>
Date: Wed Aug 19 19:16:39 2020 +0300
grltrackerwrapper: Optimize metadata queries
In GrlTrackerWrapper and GrlTrackerPlaylists queries are using generic
inefficient metadata key sets.
To optimize, add specific key sets for each type of query.
Closes: #339
gnomemusic/grilowrappers/grltrackerplaylists.py | 55 ++++++++--------
gnomemusic/grilowrappers/grltrackerwrapper.py | 86 +++++++++++++++++++------
2 files changed, 92 insertions(+), 49 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index d14a6dac..566a6762 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -36,22 +36,11 @@ import gnomemusic.utils as utils
class GrlTrackerPlaylists(GObject.GObject):
- METADATA_KEYS = [
- Grl.METADATA_KEY_ALBUM,
- Grl.METADATA_KEY_ALBUM_ARTIST,
- Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
- Grl.METADATA_KEY_ARTIST,
+ _METADATA_PLAYLIST_KEYS = [
Grl.METADATA_KEY_CHILDCOUNT,
Grl.METADATA_KEY_CREATION_DATE,
- Grl.METADATA_KEY_COMPOSER,
- Grl.METADATA_KEY_DURATION,
- Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
- Grl.METADATA_KEY_PLAY_COUNT,
- Grl.METADATA_KEY_THUMBNAIL,
- Grl.METADATA_KEY_TITLE,
- Grl.METADATA_KEY_TRACK_NUMBER,
- Grl.METADATA_KEY_URL
+ Grl.METADATA_KEY_TITLE
]
def __init__(self, source, application, tracker_wrapper, songs_hash):
@@ -123,7 +112,7 @@ class GrlTrackerPlaylists(GObject.GObject):
}
self._source.query(
- query, self.METADATA_KEYS, self._fast_options,
+ query, self._METADATA_PLAYLIST_KEYS, self._fast_options,
self._add_user_playlist)
def _add_user_playlist(
@@ -230,7 +219,7 @@ class GrlTrackerPlaylists(GObject.GObject):
}
self._source.query(
- query, self.METADATA_KEYS, self._fast_options,
+ query, self._METADATA_PLAYLIST_KEYS, self._fast_options,
self._add_user_playlist, callback)
self._notificationmanager.push_loading()
@@ -266,20 +255,15 @@ class Playlist(GObject.GObject):
"playlist-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
}
- METADATA_KEYS = [
+ _METADATA_PLAYLIST_KEYS = [
Grl.METADATA_KEY_ALBUM,
- Grl.METADATA_KEY_ALBUM_ARTIST,
- Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
Grl.METADATA_KEY_ARTIST,
- Grl.METADATA_KEY_CREATION_DATE,
- Grl.METADATA_KEY_COMPOSER,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
+ Grl.METADATA_KEY_LAST_PLAYED,
Grl.METADATA_KEY_PLAY_COUNT,
- Grl.METADATA_KEY_THUMBNAIL,
Grl.METADATA_KEY_TITLE,
- Grl.METADATA_KEY_TRACK_NUMBER,
Grl.METADATA_KEY_URL
]
@@ -416,7 +400,8 @@ class Playlist(GObject.GObject):
Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
self._source.query(
- query, self.METADATA_KEYS, options, _add_to_playlist_cb, None)
+ query, self._METADATA_PLAYLIST_KEYS, options, _add_to_playlist_cb,
+ None)
def _bind_to_main_song(self, coresong):
main_coresong = self._songs_hash[coresong.props.media.get_id()]
@@ -657,7 +642,8 @@ class Playlist(GObject.GObject):
}
self._source.query(
- query, self.METADATA_KEYS, self._fast_options, _add_to_model)
+ query, self._METADATA_PLAYLIST_KEYS, self._fast_options,
+ _add_to_model)
for coresong in coresongs:
query = """
@@ -734,6 +720,19 @@ class Playlist(GObject.GObject):
class SmartPlaylist(Playlist):
"""Base class for smart playlists"""
+ _METADATA_SMART_PLAYLIST_KEYS = [
+ Grl.METADATA_KEY_ALBUM,
+ Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_DURATION,
+ Grl.METADATA_KEY_FAVOURITE,
+ Grl.METADATA_KEY_ID,
+ Grl.METADATA_KEY_PLAY_COUNT,
+ Grl.METADATA_KEY_URL,
+ Grl.METADATA_KEY_TITLE,
+ Grl.METADATA_KEY_TRACK_NUMBER,
+ ]
+
def __init__(self, **args):
super().__init__(**args)
@@ -764,8 +763,8 @@ class SmartPlaylist(Playlist):
self._model.append(coresong)
self._source.query(
- self.props.query, self.METADATA_KEYS, self._fast_options,
- _add_to_model)
+ self.props.query, self._METADATA_SMART_PLAYLIST_KEYS,
+ self._fast_options, _add_to_model)
return self._model
@@ -787,8 +786,8 @@ class SmartPlaylist(Playlist):
new_model_medias.append(media)
self._source.query(
- self.props.query, self.METADATA_KEYS, self._fast_options,
- _fill_new_model)
+ self.props.query, self._METADATA_SMART_PLAYLIST_KEYS,
+ self._fast_options, _fill_new_model)
def _finish_update(self, new_model_medias):
if not new_model_medias:
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 5f8cf10d..96b19897 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -40,26 +40,45 @@ class GrlTrackerWrapper(GObject.GObject):
_SPLICE_SIZE = 100
- METADATA_KEYS = [
- Grl.METADATA_KEY_ALBUM,
+ _METADATA_ALBUM_CHANGED_KEYS = [
+ Grl.METADATA_KEY_ARTIST,
Grl.METADATA_KEY_ALBUM_ARTIST,
+ Grl.METADATA_KEY_COMPOSER,
+ Grl.METADATA_KEY_CREATION_DATE,
+ Grl.METADATA_KEY_ID,
+ Grl.METADATA_KEY_TITLE,
+ Grl.METADATA_KEY_URL
+ ]
+
+ _METADATA_SONG_FILL_KEYS = [
+ Grl.METADATA_KEY_ALBUM,
Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
Grl.METADATA_KEY_ARTIST,
- Grl.METADATA_KEY_CREATION_DATE,
- Grl.METADATA_KEY_COMPOSER,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
Grl.METADATA_KEY_PLAY_COUNT,
- Grl.METADATA_KEY_THUMBNAIL,
Grl.METADATA_KEY_TITLE,
Grl.METADATA_KEY_TRACK_NUMBER,
Grl.METADATA_KEY_URL
]
- METADATA_THUMBNAIL_KEYS = [
+ _METADATA_SONG_MEDIA_QUERY_KEYS = [
+ Grl.METADATA_KEY_ALBUM,
+ Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_DURATION,
+ Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
- Grl.METADATA_KEY_THUMBNAIL,
+ Grl.METADATA_KEY_PLAY_COUNT,
+ Grl.METADATA_KEY_TITLE,
+ Grl.METADATA_KEY_TRACK_NUMBER,
+ Grl.METADATA_KEY_URL
+ ]
+
+ _METADATA_THUMBNAIL_KEYS = [
+ Grl.METADATA_KEY_ID,
+ Grl.METADATA_KEY_THUMBNAIL
]
def __init__(self, source, application, tracker_wrapper):
@@ -243,7 +262,8 @@ class GrlTrackerWrapper(GObject.GObject):
album_ids[media.get_id()] = album
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, check_album_cb)
+ query, self._METADATA_ALBUM_CHANGED_KEYS, self._fast_options,
+ check_album_cb)
def _check_artist_change(self):
artist_ids = {}
@@ -279,6 +299,12 @@ class GrlTrackerWrapper(GObject.GObject):
'location_filter': self._tracker_wrapper.location_filter()
}
+ metadata_keys = [
+ Grl.METADATA_KEY_ALBUM_ARTIST,
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_ID
+ ]
+
def check_artist_cb(source, op_id, media, remaining, error):
if error:
self._log.warning("Error: {}".format(error))
@@ -310,7 +336,7 @@ class GrlTrackerWrapper(GObject.GObject):
artist_ids[media.get_id()] = artist
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, check_artist_cb)
+ query, metadata_keys, self._fast_options, check_artist_cb)
def _remove_media(self, media_ids):
for media_id in media_ids:
@@ -399,8 +425,9 @@ class GrlTrackerWrapper(GObject.GObject):
media_ids.remove(media_id)
self.props.source.query(
- self._song_media_query(media_ids), self.METADATA_KEYS,
- self._fast_options, _update_changed_media)
+ self._song_media_query(media_ids),
+ self._METADATA_SONG_MEDIA_QUERY_KEYS, self._fast_options,
+ _update_changed_media)
def _initial_songs_fill(self):
self._notificationmanager.push_loading()
@@ -476,7 +503,8 @@ class GrlTrackerWrapper(GObject.GObject):
}
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, _add_to_model)
+ query, self._METADATA_SONG_FILL_KEYS, self._fast_options,
+ _add_to_model)
def _initial_albums_fill(self):
self._notificationmanager.push_loading()
@@ -543,7 +571,7 @@ class GrlTrackerWrapper(GObject.GObject):
}
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options,
+ query, self._METADATA_ALBUM_CHANGED_KEYS, self._fast_options,
_add_to_albums_model)
def _initial_artists_fill(self):
@@ -602,9 +630,13 @@ class GrlTrackerWrapper(GObject.GObject):
'location_filter': self._tracker_wrapper.location_filter()
}
+ metadata_keys = [
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_ID
+ ]
+
self.props.source.query(
- query, [Grl.METADATA_KEY_ARTIST], self._fast_options,
- _add_to_artists_model)
+ query, metadata_keys, self._fast_options, _add_to_artists_model)
def get_artist_albums(self, media, model):
"""Get all albums by an artist
@@ -790,8 +822,20 @@ class GrlTrackerWrapper(GObject.GObject):
'miner_fs_busname': self._tracker_wrapper.props.miner_fs_busname
}
+ metadata_keys = [
+ Grl.METADATA_KEY_ALBUM,
+ Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_DURATION,
+ Grl.METADATA_KEY_FAVOURITE,
+ Grl.METADATA_KEY_ID,
+ Grl.METADATA_KEY_PLAY_COUNT,
+ Grl.METADATA_KEY_TITLE,
+ Grl.METADATA_KEY_URL
+ ]
+
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, callback)
+ query, metadata_keys, self._fast_options, callback)
def search(self, text):
# FIXME: Searches are limited to not bog down the UI with
@@ -876,7 +920,7 @@ class GrlTrackerWrapper(GObject.GObject):
artist_filter_ids.append(media.get_id())
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, artist_search_cb)
+ query, [Grl.METADATA_KEY_ID], self._fast_options, artist_search_cb)
# Album search
self._notificationmanager.push_loading()
@@ -943,7 +987,7 @@ class GrlTrackerWrapper(GObject.GObject):
album_filter_ids.append(media.get_id())
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, albums_search_cb)
+ query, [Grl.METADATA_KEY_ID], self._fast_options, albums_search_cb)
# Song search
self._notificationmanager.push_loading()
@@ -1015,7 +1059,7 @@ class GrlTrackerWrapper(GObject.GObject):
filter_ids.append(media.get_id())
self.props.source.query(
- query, self.METADATA_KEYS, self._fast_options, songs_search_cb)
+ query, [Grl.METADATA_KEY_ID], self._fast_options, songs_search_cb)
def _get_album_for_media_id_query(self, media_id, song=True):
# Even though we check for the album_artist, we fill
@@ -1117,7 +1161,7 @@ class GrlTrackerWrapper(GObject.GObject):
query = self._get_album_for_media_id_query(song_id)
self.props.source.query(
- query, self.METADATA_THUMBNAIL_KEYS, self._full_options,
+ query, self._METADATA_THUMBNAIL_KEYS, self._full_options,
art_retrieved_cb)
def get_album_art(self, corealbum):
@@ -1149,7 +1193,7 @@ class GrlTrackerWrapper(GObject.GObject):
query = self._get_album_for_media_id_query(album_id, False)
self._source.query(
- query, self.METADATA_THUMBNAIL_KEYS, self._full_options,
+ query, self._METADATA_THUMBNAIL_KEYS, self._full_options,
art_retrieved_cb)
def get_artist_art(self, coreartist):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]