[gnome-music/wip/mschraal/grltrackerwrapper-unify-songs-query: 1/2] grltrackerwrapper: Unify songs query
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/grltrackerwrapper-unify-songs-query: 1/2] grltrackerwrapper: Unify songs query
- Date: Tue, 31 Aug 2021 21:04:06 +0000 (UTC)
commit d702ee0575409253d1899aa6056061aeb30b3c6c
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Aug 31 20:54:53 2021 +0200
grltrackerwrapper: Unify songs query
There were two very similar query statements used for songs, this is
suboptimal and error-prone.
Use one query instead.
gnomemusic/grilowrappers/grltrackerwrapper.py | 61 ++++++---------------------
1 file changed, 14 insertions(+), 47 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index c78a7cd04..e8579daf6 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -395,8 +395,16 @@ class GrlTrackerWrapper(GObject.GObject):
self._songs_model.remove(idx)
break
- def _song_media_query(self, ids: List[str]) -> str:
- media_ids: str = str(ids)[1:-1].replace("'", "")
+ def _song_media_query(self, ids: Optional[List[str]] = None) -> str:
+ """Returns a songs query string
+
+ :param list ids: List of Media ids to filter by or None
+ """
+ if ids != None:
+ media_ids = str(ids)[1:-1].replace("'", "")
+ songs_filter = f"FILTER ( ?song in ( {media_ids} ) )"
+ else:
+ songs_filter = ""
query = """
SELECT
@@ -423,7 +431,7 @@ class GrlTrackerWrapper(GObject.GObject):
AS ?albumDiscNumber
WHERE {
?song a nmm:MusicPiece .
- FILTER ( ?song in ( %(media_ids)s ) )
+ %(songs_filter)s
%(location_filter)s
}
}
@@ -437,7 +445,7 @@ class GrlTrackerWrapper(GObject.GObject):
"miner_fs_busname": self._tracker_wrapper.props.miner_fs_busname,
"media_type": int(Grl.MediaType.AUDIO),
'location_filter': self._tracker_wrapper.location_filter(),
- 'media_ids': media_ids
+ "songs_filter": songs_filter
}
return query
@@ -506,50 +514,9 @@ class GrlTrackerWrapper(GObject.GObject):
self._songs_model.get_n_items(), 0, songs_added)
songs_added.clear()
- query = """
- SELECT
- ?type ?urn ?title ?id ?url
- ?artist ?album
- ?duration ?trackNumber
- ?albumDiscNumber
- nie:usageCounter(?urn) AS ?playCount
- ?tag AS ?favorite
- WHERE {
- SERVICE <dbus:%(miner_fs_busname)s> {
- GRAPH tracker:Audio {
- SELECT
- %(media_type)s AS ?type
- ?song AS ?urn
- nie:title(?song) AS ?title
- ?song AS ?id
- nie:isStoredAs(?song) AS ?url
- nmm:artistName(nmm:artist(?song)) AS ?artist
- nie:title(nmm:musicAlbum(?song)) AS ?album
- nfo:duration(?song) AS ?duration
- nmm:trackNumber(?song) AS ?trackNumber
- nmm:setNumber(nmm:musicAlbumDisc(?song))
- AS ?albumDiscNumber
- WHERE {
- ?song a nmm:MusicPiece .
- %(location_filter)s
- }
- ORDER BY ?title
- }
- }
- OPTIONAL {
- ?urn nao:hasTag ?tag .
- FILTER (?tag = nao:predefined-tag-favorite)
- }
- }
- """.replace('\n', ' ').strip() % {
- "miner_fs_busname": self._tracker_wrapper.props.miner_fs_busname,
- "media_type": int(Grl.MediaType.AUDIO),
- 'location_filter': self._tracker_wrapper.location_filter()
- }
-
self.props.source.query(
- query, self._METADATA_SONG_FILL_KEYS, self._fast_options,
- _add_to_model)
+ self._song_media_query(), self._METADATA_SONG_FILL_KEYS,
+ self._fast_options, _add_to_model)
def _initial_albums_fill(self) -> None:
self._notificationmanager.push_loading()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]