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
=== modified file 'src/scope.vala'
--- src/scope.vala 2013-03-26 19:29:47 +0000
+++ src/scope.vala 2013-03-27 14:39:25 +0000
@@ -39,6 +39,7 @@
39 private SmartScopes.ChannelIdMap channel_id_map = new SmartScopes.ChannelIdMap ();39 private SmartScopes.ChannelIdMap channel_id_map = new SmartScopes.ChannelIdMap ();
40 private uint metrics_timer;40 private uint metrics_timer;
41 private int remote_scopes_retry_count = 0;41 private int remote_scopes_retry_count = 0;
42 private HashTable<string, GLib.Cancellable?> search_cancel = new HashTable<string, GLib.Cancellable?> (str_hash, str_equal);
42 private RemoteScopeRegistry remote_scope_registry;43 private RemoteScopeRegistry remote_scope_registry;
4344
44 public HomeScope ()45 public HomeScope ()
@@ -412,6 +413,16 @@
412413
413 CategoryManager.instance ().observe (scope_search.channel_id, scope_search.results_model);414 CategoryManager.instance ().observe (scope_search.channel_id, scope_search.results_model);
414415
416 GLib.Cancellable? prev_search = search_cancel.lookup (scope_search.channel_id);
417 if (prev_search != null)
418 {
419 debug ("Cancelling previous search query for channel: %s", scope_search.channel_id);
420 prev_search.cancel ();
421 }
422
423 GLib.Cancellable cancellable = new GLib.Cancellable ();
424 search_cancel.insert (scope_search.channel_id, cancellable);
425
415 bool wait_for_sss_query = false;426 bool wait_for_sss_query = false;
416 bool wait_for_push = false;427 bool wait_for_push = false;
417 bool wait_for_search = false;428 bool wait_for_search = false;
@@ -575,6 +586,21 @@
575 remote_scopes_to_query += scope_id;586 remote_scopes_to_query += scope_id;
576 }587 }
577588
589 // timeout to give cancellable a chance for update; it depends on query length (the longer the string, the shorter timeout)
590 GLib.Timeout.add (int.max (20, 100/(scope_search.search_string.length + 1)), ()=>
591 {
592 if (wait_for_search == false && wait_for_push == false && wait_for_sss_query == false)
593 search.callback ();
594 return false;
595 });
596 yield;
597
598 if (cancellable.is_cancelled ())
599 {
600 debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
601 return;
602 }
603
578 sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query, scope_mgr.disabled_scopes,604 sss_client.search.begin (scope_search.search_string, session_id, remote_scopes_to_query, scope_mgr.disabled_scopes,
579 (scope_id, row) =>605 (scope_id, row) =>
580 {606 {
@@ -607,8 +633,7 @@
607 {633 {
608 warning ("server_sid is null");634 warning ("server_sid is null");
609 }635 }
610 }, null, //TODO cancellable636 }, cancellable, sss_cb);
611 sss_cb);
612 }637 }
613 }638 }
614 else639 else
@@ -664,20 +689,30 @@
664 yield;689 yield;
665 }690 }
666691
667 signal_categories_order (scope_search, recommended_search_scopes);692 try
668
669 if (push_data_idle_src > 0)
670 {693 {
671 debug ("Flushing push results");694 cancellable.set_error_if_cancelled ();
672 push_data_idle_cb (); //make sure we flush all push_results695
673 if (pending_push_count > 0)696 signal_categories_order (scope_search, recommended_search_scopes);
697
698 if (push_data_idle_src > 0)
674 {699 {
675 debug ("Waiting for results pushing to finish");700 debug ("Flushing push results");
676 wait_for_push = true;701 push_data_idle_cb (); //make sure we flush all push_results
677 yield;702 if (pending_push_count > 0)
703 {
704 debug ("Waiting for results pushing to finish");
705 wait_for_push = true;
706 yield;
707 }
678 }708 }
679 Source.remove (push_data_idle_src);709 }
710 finally
711 {
712 if (push_data_idle_src > 0)
713 Source.remove (push_data_idle_src);
680 push_data_idle_src = 0;714 push_data_idle_src = 0;
715 debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
681 }716 }
682717
683 debug ("Got %u recommended scopes from Smart Scope Service", recommended_search_scopes.length ());718 debug ("Got %u recommended scopes from Smart Scope Service", recommended_search_scopes.length ());
@@ -745,6 +780,12 @@
745 yield;780 yield;
746 }781 }
747 782
783 if (cancellable.is_cancelled ())
784 {
785 debug ("The search for '%s' on channel %s was cancelled", scope_search.search_string, scope_search.channel_id);
786 return;
787 }
788
748 debug ("search finished");789 debug ("search finished");
749790
750 signal_categories_order (scope_search, recommended_search_scopes);791 signal_categories_order (scope_search, recommended_search_scopes);
751792
=== modified file 'src/smart-scopes-search.vala'
--- src/smart-scopes-search.vala 2013-03-22 19:40:37 +0000
+++ src/smart-scopes-search.vala 2013-03-27 14:39:25 +0000
@@ -114,6 +114,7 @@
114 try114 try
115 {115 {
116 msg = yield queue_soup_message (session, msg, cancellable);116 msg = yield queue_soup_message (session, msg, cancellable);
117 cancellable.set_error_if_cancelled ();
117 if (msg.status_code == 200)118 if (msg.status_code == 200)
118 finalize_parsing ();119 finalize_parsing ();
119 }120 }
@@ -146,7 +147,6 @@
146147
147 b.set_member_name ("metadata");148 b.set_member_name ("metadata");
148149
149
150 var content = result.metadata.lookup ("content"); //master scopes put 'metadata' in 'content'150 var content = result.metadata.lookup ("content"); //master scopes put 'metadata' in 'content'
151 var metadata_var = content;151 var metadata_var = content;
152152

Subscribers

People subscribed via source and target branches

to all changes: