Merge lp:~stolowski/unity-scope-home/cancellables into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 93
Merged at revision: 80
Proposed branch: lp:~stolowski/unity-scope-home/cancellables
Merge into: lp:unity-scope-home
Prerequisite: lp:~stolowski/unity-scope-home/more-async
Diff against target: 133 lines (+54/-13)
2 files modified
src/scope.vala (+53/-12)
src/smart-scopes-search.vala (+1/-1)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/cancellables
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+155576@code.launchpad.net

Commit message

Cancel previous search on new one in same channel.

Description of the change

Cancel previous search on new one in same channel.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

34 + GLib.Timeout.add (int.max (20, 100/(scope_search.search_string.length + 1)), ()=> { return false; });

You need to yield for this to actually do something :)

review: Needs Fixing
87. By Paweł Stołowski

Merged more-async.

88. By Paweł Stołowski

Merged more-async.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

49 + }, cancellable, //TODO cancellable

Looks like that TODO is done :)

89. By Paweł Stołowski

Merged trunk.

90. By Paweł Stołowski

Yield after creating a Timeout source. Remove idle source on cancellation.

91. By Paweł Stołowski

Fix - one more removal of idle before cancellation.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
92. By Paweł Stołowski

Use cancellable.set_error_if_cancelled to simplify idle source removal.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

57 + }, cancellable, sss_cb);

I'm a bit worried that there are no extra cancellable checks inside the SSSClient implementation, isn't it possible that it's cancelled after the query finishes but before the json parsing is done? In that case the callbacks will still be called and could cause a crash.

108 + debug ("The search for channel %s was cancelled", scope_search.channel_id);

Will be more useful if you also log the current search_query.

93. By Paweł Stołowski

Check cancellable before finalizing parsing in smart scopes search method.

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

> 57 + }, cancellable, sss_cb);
>
> I'm a bit worried that there are no extra cancellable checks inside the
> SSSClient implementation, isn't it possible that it's cancelled after the
> query finishes but before the json parsing is done? In that case the callbacks
> will still be called and could cause a crash.

Added an extra check before calling finalize_parsing (after soup request finished) - I think that's the only case that needs that.

>
> 108 + debug ("The search for channel %s was cancelled",
> scope_search.channel_id);
>
> Will be more useful if you also log the current search_query.

Done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

Let's get this in.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/scope.vala'
2--- src/scope.vala 2013-03-26 19:29:47 +0000
3+++ src/scope.vala 2013-03-27 14:39:25 +0000
4@@ -39,6 +39,7 @@
5 private SmartScopes.ChannelIdMap channel_id_map = new SmartScopes.ChannelIdMap ();
6 private uint metrics_timer;
7 private int remote_scopes_retry_count = 0;
8+ private HashTable<string, GLib.Cancellable?> search_cancel = new HashTable<string, GLib.Cancellable?> (str_hash, str_equal);
9 private RemoteScopeRegistry remote_scope_registry;
10
11 public HomeScope ()
12@@ -412,6 +413,16 @@
13
14 CategoryManager.instance ().observe (scope_search.channel_id, scope_search.results_model);
15
16+ GLib.Cancellable? prev_search = search_cancel.lookup (scope_search.channel_id);
17+ if (prev_search != null)
18+ {
19+ debug ("Cancelling previous search query for channel: %s", scope_search.channel_id);
20+ prev_search.cancel ();
21+ }
22+
23+ GLib.Cancellable cancellable = new GLib.Cancellable ();
24+ search_cancel.insert (scope_search.channel_id, cancellable);
25+
26 bool wait_for_sss_query = false;
27 bool wait_for_push = false;
28 bool wait_for_search = false;
29@@ -575,6 +586,21 @@
30 remote_scopes_to_query += scope_id;
31 }
32
33+ // timeout to give cancellable a chance for update; it depends on query length (the longer the string, the shorter timeout)
34+ GLib.Timeout.add (int.max (20, 100/(scope_search.search_string.length + 1)), ()=>
35+ {
36+ if (wait_for_search == false && wait_for_push == false && wait_for_sss_query == false)
37+ search.callback ();
38+ return false;
39+ });
40+ yield;
41+
42+ if (cancellable.is_cancelled ())
43+ {
44+ debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
45+ return;
46+ }
47+
48 sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query, scope_mgr.disabled_scopes,
49 (scope_id, row) =>
50 {
51@@ -607,8 +633,7 @@
52 {
53 warning ("server_sid is null");
54 }
55- }, null, //TODO cancellable
56- sss_cb);
57+ }, cancellable, sss_cb);
58 }
59 }
60 else
61@@ -664,20 +689,30 @@
62 yield;
63 }
64
65- signal_categories_order (scope_search, recommended_search_scopes);
66-
67- if (push_data_idle_src > 0)
68+ try
69 {
70- debug ("Flushing push results");
71- push_data_idle_cb (); //make sure we flush all push_results
72- if (pending_push_count > 0)
73+ cancellable.set_error_if_cancelled ();
74+
75+ signal_categories_order (scope_search, recommended_search_scopes);
76+
77+ if (push_data_idle_src > 0)
78 {
79- debug ("Waiting for results pushing to finish");
80- wait_for_push = true;
81- yield;
82+ debug ("Flushing push results");
83+ push_data_idle_cb (); //make sure we flush all push_results
84+ if (pending_push_count > 0)
85+ {
86+ debug ("Waiting for results pushing to finish");
87+ wait_for_push = true;
88+ yield;
89+ }
90 }
91- Source.remove (push_data_idle_src);
92+ }
93+ finally
94+ {
95+ if (push_data_idle_src > 0)
96+ Source.remove (push_data_idle_src);
97 push_data_idle_src = 0;
98+ debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
99 }
100
101 debug ("Got %u recommended scopes from Smart Scope Service", recommended_search_scopes.length ());
102@@ -745,6 +780,12 @@
103 yield;
104 }
105
106+ if (cancellable.is_cancelled ())
107+ {
108+ debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
109+ return;
110+ }
111+
112 debug ("search finished");
113
114 signal_categories_order (scope_search, recommended_search_scopes);
115
116=== modified file 'src/smart-scopes-search.vala'
117--- src/smart-scopes-search.vala 2013-03-22 19:40:37 +0000
118+++ src/smart-scopes-search.vala 2013-03-27 14:39:25 +0000
119@@ -114,6 +114,7 @@
120 try
121 {
122 msg = yield queue_soup_message (session, msg, cancellable);
123+ cancellable.set_error_if_cancelled ();
124 if (msg.status_code == 200)
125 finalize_parsing ();
126 }
127@@ -146,7 +147,6 @@
128
129 b.set_member_name ("metadata");
130
131-
132 var content = result.metadata.lookup ("content"); //master scopes put 'metadata' in 'content'
133 var metadata_var = content;
134

Subscribers

People subscribed via source and target branches

to all changes: