From 9bd2359464568c1fceb6ca4b000be8e5fe51719c Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Thu, 5 Nov 2020 18:56:11 +1100 Subject: [PATCH] Geary.Account: Make new_search_query synchronous Constructing a new query should be fast, and it no longer needs to be done async, so remove async from the method and simplify callers. --- .../application/application-main-window.vala | 9 ++++----- .../conversation-viewer.vala | 17 ++++++----------- src/engine/api/geary-account.vala | 5 ++--- .../imap-engine-generic-account.vala | 5 ++--- test/mock/mock-account.vala | 7 +++---- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala index c4f93431..18016410 100644 --- a/src/client/application/application-main-window.vala +++ b/src/client/application/application-main-window.vala @@ -968,7 +968,7 @@ public class Application.MainWindow : return closed; } - internal async void start_search(string query_text, bool is_interactive) { + internal void start_search(string query_text, bool is_interactive) { var context = get_selected_account_context(); if (context != null) { // Stop any search in progress @@ -986,10 +986,9 @@ public class Application.MainWindow : this.application.config.get_search_strategy(), context.account.information ); - var query = yield context.account.new_search_query( + var query = context.account.new_search_query( expr_factory.parse_query(query_text), - query_text, - cancellable + query_text ); this.folder_list.set_search( this.application.engine, context.search @@ -2219,7 +2218,7 @@ public class Application.MainWindow : if (Geary.String.is_empty_or_whitespace(text)) { stop_search(true); } else { - this.start_search.begin(text, true); + this.start_search(text, true); } } diff --git a/src/client/conversation-viewer/conversation-viewer.vala b/src/client/conversation-viewer/conversation-viewer.vala index 09d25020..4d895db4 100644 --- a/src/client/conversation-viewer/conversation-viewer.vala +++ b/src/client/conversation-viewer/conversation-viewer.vala @@ -297,9 +297,7 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface { // Highlight matching terms from find if active, otherwise // from the search folder if that's where we are at - Geary.SearchQuery? query = yield get_find_search_query( - conversation.base_folder.account, null - ); + var query = get_find_search_query(conversation.base_folder.account); if (query == null) { var search_folder = conversation.base_folder as Geary.App.SearchFolder; if (search_folder != null) { @@ -406,9 +404,8 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface { }); this.find_cancellable = cancellable; try { - Geary.SearchQuery? query = yield get_find_search_query( - list.conversation.base_folder.account, - cancellable + var query = get_find_search_query( + list.conversation.base_folder.account ); if (query != null) { yield list.search.highlight_matching_email(query, true); @@ -419,8 +416,7 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface { } } - private async Geary.SearchQuery? get_find_search_query(Geary.Account account, - GLib.Cancellable? cancellable) + private Geary.SearchQuery? get_find_search_query(Geary.Account account) throws GLib.Error { Geary.SearchQuery? query = null; if (this.conversation_find_bar.get_search_mode()) { @@ -433,10 +429,9 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface { this.config.get_search_strategy(), account.information ); - query = yield account.new_search_query( + query = account.new_search_query( expr_factory.parse_query(text), - text, - cancellable + text ); } } diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala index 6bba6b90..bc887459 100644 --- a/src/engine/api/geary-account.vala +++ b/src/engine/api/geary-account.vala @@ -514,10 +514,9 @@ public abstract class Geary.Account : BaseObject, Logging.Source { /** * Create a new search query for this account. */ - public abstract async SearchQuery new_search_query( + public abstract SearchQuery new_search_query( Gee.List expression, - string text, - GLib.Cancellable? cancellable + string text ) throws GLib.Error; /** diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala b/src/engine/imap-engine/imap-engine-generic-account.vala index 68ed4efc..c3ae2603 100644 --- a/src/engine/imap-engine/imap-engine-generic-account.vala +++ b/src/engine/imap-engine/imap-engine-generic-account.vala @@ -575,10 +575,9 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account { } /** {@inheritDoc} */ - public override async SearchQuery new_search_query( + public override SearchQuery new_search_query( Gee.List expression, - string text, - GLib.Cancellable? cancellable + string text ) throws GLib.Error { return new FtsSearchQuery(expression, text, this.stemmer); } diff --git a/test/mock/mock-account.vala b/test/mock/mock-account.vala index 2d08314d..f617f969 100644 --- a/test/mock/mock-account.vala +++ b/test/mock/mock-account.vala @@ -222,12 +222,11 @@ public class Mock.Account : Geary.Account, ); } - public override async Geary.SearchQuery new_search_query( + public override Geary.SearchQuery new_search_query( Gee.List expression, - string raw, - GLib.Cancellable? cancellable + string text ) throws GLib.Error { - return new SearchQuery(expression, raw); + return new SearchQuery(expression, text); } public override async Gee.Collection?