[gnome-software/1731-search-for-apps-text-shows-up-instead-of-a-spinner-screen-randomly] gs-search-page: Ignore finished non-current searches
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1731-search-for-apps-text-shows-up-instead-of-a-spinner-screen-randomly] gs-search-page: Ignore finished non-current searches
- Date: Wed, 31 Aug 2022 13:01:24 +0000 (UTC)
commit b1ecb75a7aa0967d050b805652139092b1d2a256
Author: Milan Crha <mcrha redhat com>
Date: Mon Aug 22 12:54:23 2022 +0200
gs-search-page: Ignore finished non-current searches
The search can take various time and even the cancellable is cancelled
due to the search term change or anything like that, the code can be
far away from the place where the cancellable could be checked, which
means even the search was obsolete it could modify the content of the page.
Let the code check whether the finished search is still the current
search and ignore any result from it when it's an obsolete search.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1731
src/gs-search-page.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index b86f7389a..3b54c2c5c 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -34,6 +34,7 @@ struct _GsSearchPage
gchar *value;
guint waiting_id;
guint max_results;
+ guint stamp;
gboolean changed;
GtkWidget *list_box_search;
@@ -96,19 +97,29 @@ gs_search_page_app_to_show_created_cb (GObject *source_object,
}
}
+typedef struct {
+ GsSearchPage *self;
+ guint stamp;
+} GetSearchData;
+
static void
gs_search_page_get_search_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
guint i;
+ g_autofree GetSearchData *search_data = user_data;
GsApp *app;
- GsSearchPage *self = GS_SEARCH_PAGE (user_data);
+ GsSearchPage *self = search_data->self;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
GtkWidget *app_row;
g_autoptr(GError) error = NULL;
g_autoptr(GsAppList) list = NULL;
+ /* different stamps means another search had been started before this one finished */
+ if (search_data->stamp != self->stamp)
+ return;
+
/* don't do the delayed spinner */
gs_search_page_waiting_cancel (self);
@@ -265,6 +276,7 @@ gs_search_page_load (GsSearchPage *self)
g_autoptr(GsPluginJob) plugin_job = NULL;
g_autoptr(GsAppQuery) query = NULL;
const gchar *keywords[2] = { NULL, };
+ g_autofree GetSearchData *search_data = NULL;
self->changed = FALSE;
@@ -272,11 +284,16 @@ gs_search_page_load (GsSearchPage *self)
g_cancellable_cancel (self->search_cancellable);
g_clear_object (&self->search_cancellable);
self->search_cancellable = g_cancellable_new ();
+ self->stamp++;
/* search for apps */
gs_search_page_waiting_cancel (self);
self->waiting_id = g_timeout_add (250, gs_search_page_waiting_show_cb, self);
+ search_data = g_new0 (GetSearchData, 1);
+ search_data->self = self;
+ search_data->stamp = self->stamp;
+
keywords[0] = self->value;
query = gs_app_query_new ("keywords", keywords,
"refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
@@ -298,7 +315,7 @@ gs_search_page_load (GsSearchPage *self)
gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
self->search_cancellable,
gs_search_page_get_search_cb,
- self);
+ g_steal_pointer (&search_data));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]