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
1=== modified file 'src/musicstore-collection.vala'
2--- src/musicstore-collection.vala 2012-02-06 22:19:44 +0000
3+++ src/musicstore-collection.vala 2012-07-11 08:06:22 +0000
4@@ -25,6 +25,7 @@
5 {
6
7 private const string MUSICSTORE_BASE_URI = "http://musicsearch.ubuntu.com/v1/";
8+ private const uint PURCHASE_CATEGORY = 2;
9
10 public MusicStoreCollection ()
11 {
12@@ -56,34 +57,51 @@
13 yield parser.load_from_stream_async (dis, cancellable);
14 var root_object = parser.get_root ().get_object ();
15
16- foreach (var r in root_object.get_array_member ("results").get_elements ()) {
17- var result_obj = r.get_object ();
18-
19- string type = result_obj.get_string_member ("type");
20- if (type == "track") {
21- Track track = new Track ();
22- track.title = result_obj.get_string_member ("title");
23- track.artist = result_obj.get_string_member ("artist");
24- track.uri = result_obj.get_string_member ("purchase_url");
25- track.artwork_path = result_obj.get_string_member ("image");
26- track.mime_type = "audio-x-generic";
27-
28- // FIXME drag n drop uri needs to be the u1ms:// link
29- model.append (track.uri, track.artwork_path, 2, track.mime_type, track.title, track.artist, track.uri);
30-
31- } else if (type == "album") {
32- Album album = new Album ();
33- album.title = result_obj.get_string_member ("title");
34- album.artist = result_obj.get_string_member ("artist");
35- album.uri = result_obj.get_string_member ("purchase_url");
36- album.artwork_path = result_obj.get_string_member ("image");
37-
38- model.append (album.uri, album.artwork_path, 2, "audio-x-generic", album.title, album.artist, album.uri);
39- }
40+ Json.Object? results = root_object.get_object_member ("results");
41+ if (results == null) {
42+ warning ("Invalid response from server. No 'results' member.");
43+ return;
44+ }
45+
46+ var albums = results.get_array_member ("album").get_elements ();
47+ var tracks = results.get_array_member ("track").get_elements ();
48+
49+ debug ("Got %u albums and %u tracks", albums.length (), tracks.length ());
50+
51+ unowned string? uri, artwork_path, mimetype, title, artist, dnd_uri;
52+
53+ foreach (var album_node in albums) {
54+ var album_obj = album_node.get_object ();
55+
56+ uri = album_obj.get_string_member ("purchase_url");
57+ artwork_path = album_obj.get_string_member ("image");
58+ mimetype = "audio-x-generic";
59+ title = album_obj.get_string_member ("title");
60+ artist = album_obj.get_string_member ("artist");
61+ dnd_uri = uri;
62+
63+ model.append (uri, artwork_path, PURCHASE_CATEGORY,
64+ mimetype, title, artist, dnd_uri);
65 }
66+
67+ foreach (var track_node in tracks) {
68+ var track_obj = track_node.get_object ();
69+
70+ uri = track_obj.get_string_member ("purchase_url");
71+ artwork_path = track_obj.get_string_member ("image");
72+ mimetype = "audio-x-generic";
73+ title = track_obj.get_string_member ("title");
74+ artist = track_obj.get_string_member ("artist");
75+ dnd_uri = uri;
76+
77+ // FIXME drag n drop uri needs to be the u1ms:// link
78+
79+ model.append (uri, artwork_path, PURCHASE_CATEGORY,
80+ mimetype, title, artist, dnd_uri);
81+ }
82
83 debug ("Retrieved '%s' in %fms", file.get_uri (), timer.elapsed()*1000);
84- debug ("model has %u rows after search", model.get_n_rows ());
85+ debug ("Model has %u rows after search", model.get_n_rows ());
86
87 } catch (Error e) {
88 warning ("Error reading URL '%s': %s", file.get_uri (), e.message);
89@@ -116,6 +134,13 @@
90 }
91
92 uri.append ("&pagesize=10");
93+
94+ // This makes the service return $pagesize results *per content type*.
95+ // Which we need - as it could otherwise return $pagesize results mixed
96+ // or artist,album, and track. Since we can't display artists, this can
97+ // lead to an empty result set in the dash if there is only artists in
98+ // the response from the webservice
99+ uri.append ("&grouping=1");
100
101 return uri.str;
102 }

Subscribers

People subscribed via source and target branches

to all changes: