Merge lp:~unity-team/unity-lens-music/improved-search-results-5.0 into lp:unity-lens-music/5.0

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Approved by: Michal Hruby
Approved revision: 83
Merged at revision: 83
Proposed branch: lp:~unity-team/unity-lens-music/improved-search-results-5.0
Merge into: lp:unity-lens-music/5.0
Diff against target: 102 lines (+50/-25)
1 file modified
src/musicstore-collection.vala (+50/-25)
To merge this branch: bzr merge lp:~unity-team/unity-lens-music/improved-search-results-5.0
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+114349@code.launchpad.net

Commit message

Fix u1 search results to not seem too random. Lowers mem churn in musicstore scope quite a bit.

Description of the change

Backport from trunk: Fix u1 search results to not seem too random. Lowers mem churn in musicstore scope quite a bit.

This was rooted in the fact that musicsearch.ubuntu.com returns a mix of artists, albums, and tracks in the results. We do not show artists, so if the results contains mainly that, then we're screwed (even though there could be many potential track/album matches outside the fetched results). Luckily newer versions of the webservice contains some parameters to tweak this behaviour. This commit makes us use that.

In addition to using the new musicsearch API I also lowered memory churn quite considerably by removing the need to create a lot of Track/Album objects and do excessive string copying.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Looking good. LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/musicstore-collection.vala'
--- src/musicstore-collection.vala 2012-02-06 22:19:44 +0000
+++ src/musicstore-collection.vala 2012-07-11 08:06:22 +0000
@@ -25,6 +25,7 @@
25 {25 {
2626
27 private const string MUSICSTORE_BASE_URI = "http://musicsearch.ubuntu.com/v1/";27 private const string MUSICSTORE_BASE_URI = "http://musicsearch.ubuntu.com/v1/";
28 private const uint PURCHASE_CATEGORY = 2;
2829
29 public MusicStoreCollection ()30 public MusicStoreCollection ()
30 {31 {
@@ -56,34 +57,51 @@
56 yield parser.load_from_stream_async (dis, cancellable);57 yield parser.load_from_stream_async (dis, cancellable);
57 var root_object = parser.get_root ().get_object ();58 var root_object = parser.get_root ().get_object ();
58 59
59 foreach (var r in root_object.get_array_member ("results").get_elements ()) {60 Json.Object? results = root_object.get_object_member ("results");
60 var result_obj = r.get_object ();61 if (results == null) {
61 62 warning ("Invalid response from server. No 'results' member.");
62 string type = result_obj.get_string_member ("type");63 return;
63 if (type == "track") {64 }
64 Track track = new Track ();65
65 track.title = result_obj.get_string_member ("title");66 var albums = results.get_array_member ("album").get_elements ();
66 track.artist = result_obj.get_string_member ("artist");67 var tracks = results.get_array_member ("track").get_elements ();
67 track.uri = result_obj.get_string_member ("purchase_url");68
68 track.artwork_path = result_obj.get_string_member ("image");69 debug ("Got %u albums and %u tracks", albums.length (), tracks.length ());
69 track.mime_type = "audio-x-generic";70
7071 unowned string? uri, artwork_path, mimetype, title, artist, dnd_uri;
71 // FIXME drag n drop uri needs to be the u1ms:// link72
72 model.append (track.uri, track.artwork_path, 2, track.mime_type, track.title, track.artist, track.uri);73 foreach (var album_node in albums) {
73 74 var album_obj = album_node.get_object ();
74 } else if (type == "album") {75
75 Album album = new Album ();76 uri = album_obj.get_string_member ("purchase_url");
76 album.title = result_obj.get_string_member ("title");77 artwork_path = album_obj.get_string_member ("image");
77 album.artist = result_obj.get_string_member ("artist");78 mimetype = "audio-x-generic";
78 album.uri = result_obj.get_string_member ("purchase_url");79 title = album_obj.get_string_member ("title");
79 album.artwork_path = result_obj.get_string_member ("image");80 artist = album_obj.get_string_member ("artist");
80 81 dnd_uri = uri;
81 model.append (album.uri, album.artwork_path, 2, "audio-x-generic", album.title, album.artist, album.uri);82
82 }83 model.append (uri, artwork_path, PURCHASE_CATEGORY,
84 mimetype, title, artist, dnd_uri);
83 }85 }
86
87 foreach (var track_node in tracks) {
88 var track_obj = track_node.get_object ();
89
90 uri = track_obj.get_string_member ("purchase_url");
91 artwork_path = track_obj.get_string_member ("image");
92 mimetype = "audio-x-generic";
93 title = track_obj.get_string_member ("title");
94 artist = track_obj.get_string_member ("artist");
95 dnd_uri = uri;
96
97 // FIXME drag n drop uri needs to be the u1ms:// link
98
99 model.append (uri, artwork_path, PURCHASE_CATEGORY,
100 mimetype, title, artist, dnd_uri);
101 }
84102
85 debug ("Retrieved '%s' in %fms", file.get_uri (), timer.elapsed()*1000);103 debug ("Retrieved '%s' in %fms", file.get_uri (), timer.elapsed()*1000);
86 debug ("model has %u rows after search", model.get_n_rows ());104 debug ("Model has %u rows after search", model.get_n_rows ());
87105
88 } catch (Error e) {106 } catch (Error e) {
89 warning ("Error reading URL '%s': %s", file.get_uri (), e.message);107 warning ("Error reading URL '%s': %s", file.get_uri (), e.message);
@@ -116,6 +134,13 @@
116 }134 }
117 135
118 uri.append ("&pagesize=10");136 uri.append ("&pagesize=10");
137
138 // This makes the service return $pagesize results *per content type*.
139 // Which we need - as it could otherwise return $pagesize results mixed
140 // or artist,album, and track. Since we can't display artists, this can
141 // lead to an empty result set in the dash if there is only artists in
142 // the response from the webservice
143 uri.append ("&grouping=1");
119144
120 return uri.str;145 return uri.str;
121 }146 }

Subscribers

People subscribed via source and target branches

to all changes: