Merge lp:~mhr3/unity-lens-video/fix-1079699 into lp:unity-lens-video/remote-videos-scope-trunk

Proposed by Michal Hruby
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 65
Merged at revision: 59
Proposed branch: lp:~mhr3/unity-lens-video/fix-1079699
Merge into: lp:unity-lens-video/remote-videos-scope-trunk
Diff against target: 79 lines (+10/-26)
1 file modified
src/unity-scope-video-remote (+10/-26)
To merge this branch: bzr merge lp:~mhr3/unity-lens-video/fix-1079699
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
John Lenton (community) Approve
Review via email: mp+137786@code.launchpad.net

Commit message

Ensure we query the videosearch server only when the data is needed

Description of the change

There was a bug in the remote video scope, which caused it to query the videosearch server every 5 minutes from non-US regions.

Ensure we query the videosearch server only when the data is needed.

To post a comment you must log in.
64. By Michal Hruby

Merge trunk

Revision history for this message
John Lenton (chipaca) wrote :

OK. Not sure I like the behaviour change, but I'm OK with it.

review: Approve
65. By Michal Hruby

Remove extra PreferencesManager call

Revision history for this message
Paweł Stołowski (stolowski) wrote :

75 + if not search.props.search_string.strip() and not sources and results:

Why 'not sources'?

review: Needs Information
Revision history for this message
Michal Hruby (mhr3) wrote :

> 75 + if not search.props.search_string.strip() and not sources and
> results:
>
> Why 'not sources'?

Cause we want to cache only empty, non-filtered search.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Right. Ok, LGTM and works fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-scope-video-remote'
2--- src/unity-scope-video-remote 2012-10-11 21:27:49 +0000
3+++ src/unity-scope-video-remote 2012-12-06 10:06:18 +0000
4@@ -79,6 +79,7 @@
5 self._pending = None
6 self.sources_list = []
7 self.recommendations = []
8+ self.recommendations_last_update = 0
9 self.scope = Unity.Scope.new("/net/launchpad/scope/remotevideos")
10 self.scope.search_in_global = False
11 self.scope.connect("search-changed", self.on_search_changed)
12@@ -93,33 +94,11 @@
13 self.session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
14 self.preferences = Unity.PreferencesManager.get_default()
15 self.query_list_of_sources()
16- self.update_recommendations()
17 self.preferences.connect("notify::remote-content-search", self.on_filtering_or_preference_changed)
18 self.scope.export()
19 # refresh the at least once every 30 minutes
20 GLib.timeout_add_seconds(REFRESH_INTERVAL/2, self.refresh_online_videos)
21
22- def update_recommendations(self):
23- """Query the server for 'recommendations'.
24-
25- In v0 extended, that means simply do an empty search with Amazon
26- as the source since it's the only paid provider at the moment.
27- """
28- if self.preferences.props.remote_content_search != Unity.PreferencesManagerRemoteContent.ALL:
29- return
30- msg = Soup.Message.new("GET", SERVER + "/search?q=&sources=Amazon")
31- self.session.queue_message(msg, self._recs_cb, None)
32-
33- def _recs_cb(self, session, msg, user_data):
34- recs = self._handle_search_msg(msg)
35- print "Got %d recommendations from the server" % len(recs)
36- if recs:
37- self.recommendations = recs
38- dt = REFRESH_INTERVAL
39- else:
40- dt = RETRY_INTERVAL
41- GLib.timeout_add_seconds(dt, self.update_recommendations)
42-
43 def query_list_of_sources(self):
44 """Query the server for a list of sources that will be used
45 to build sources filter options and search queries."""
46@@ -269,8 +248,9 @@
47
48 def get_results(self, search_string, search, model, sources):
49 """Query the server with the search string and the list of sources."""
50- if not search_string and not sources and self.recommendations:
51- self.update_results_model(search, model, self.recommendations, True)
52+ if not search_string and not sources and self.recommendations and \
53+ time.time()-self.recommendations_last_update < REFRESH_INTERVAL:
54+ self.update_results_model(search, model, self.recommendations)
55 return
56 if self._pending is not None:
57 self.session.cancel_message(self._pending,
58@@ -285,15 +265,19 @@
59 self._pending = Soup.Message.new("GET", url)
60 self.session.queue_message(self._pending,
61 self._search_cb,
62- (search, model))
63+ (search, model, sources))
64
65- def _search_cb(self, session, msg, (search, model)):
66+ def _search_cb(self, session, msg, (search, model, sources)):
67 if msg is not self._pending:
68 # nothing to do here
69 print "WAT? _search_cb snuck in on a non-pending msg"
70 return
71 self._pending = None
72 results = self._handle_search_msg(msg)
73+ # cache no-query results
74+ if not search.props.search_string.strip() and not sources and results:
75+ self.recommendations = results
76+ self.recommendations_last_update = time.time()
77 self.update_results_model(search, model, results)
78
79 def _handle_search_msg(self, msg):

Subscribers

People subscribed via source and target branches

to all changes: