[gnome-software: 9/11] appstream: Skip work in refine_categories_async() if not needed




commit 86c49f41df2c642f0f2ca44683352d437af72070
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Jul 15 16:10:07 2022 +0100

    appstream: Skip work in refine_categories_async() if not needed
    
    This makes it clearer how the refine flags are meant to be used, and
    means that getting the category list can be a lot faster if the call
    site doesn’t want to know the category sizes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-appstream.c                  |  8 ++++----
 lib/gs-appstream.h                  |  2 +-
 lib/gs-cmd.c                        |  2 +-
 lib/gs-plugin-types.h               |  2 ++
 plugins/core/gs-plugin-appstream.c  |  9 ++++++++-
 plugins/flatpak/gs-flatpak.c        | 13 ++++++-------
 plugins/flatpak/gs-flatpak.h        |  2 +-
 plugins/flatpak/gs-plugin-flatpak.c |  9 ++++++++-
 src/gs-overview-page.c              |  3 ++-
 9 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index a1bce7a92..78f6e5598 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -1632,10 +1632,10 @@ gs_appstream_count_component_for_groups (XbSilo      *silo,
 /* we're not actually adding categories here, we're just setting the number of
  * applications available in each category */
 gboolean
-gs_appstream_add_categories (XbSilo *silo,
-                            GPtrArray *list,
-                            GCancellable *cancellable,
-                            GError **error)
+gs_appstream_refine_category_sizes (XbSilo        *silo,
+                                    GPtrArray     *list,
+                                    GCancellable  *cancellable,
+                                    GError       **error)
 {
        g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
        g_return_val_if_fail (list != NULL, FALSE);
diff --git a/lib/gs-appstream.h b/lib/gs-appstream.h
index 069208007..d0d6ea25c 100644
--- a/lib/gs-appstream.h
+++ b/lib/gs-appstream.h
@@ -35,7 +35,7 @@ gboolean       gs_appstream_search_developer_apps     (GsPlugin       *plugin,
                                                         GsAppList      *list,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
-gboolean        gs_appstream_add_categories            (XbSilo         *silo,
+gboolean        gs_appstream_refine_category_sizes     (XbSilo         *silo,
                                                         GPtrArray      *list,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index 7070bf032..895e1b80c 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -742,7 +742,7 @@ main (int argc, char **argv)
        } else if (argc == 2 && g_strcmp0 (argv[1], "get-categories") == 0) {
                for (i = 0; i < repeat; i++) {
                        g_autoptr(GsPluginJob) plugin_job = NULL;
-                       GsPluginRefineCategoriesFlags flags = GS_PLUGIN_REFINE_CATEGORIES_FLAGS_NONE;
+                       GsPluginRefineCategoriesFlags flags = GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE;
 
                        if (categories != NULL)
                                g_ptr_array_unref (categories);
diff --git a/lib/gs-plugin-types.h b/lib/gs-plugin-types.h
index 038976adf..59504bea9 100644
--- a/lib/gs-plugin-types.h
+++ b/lib/gs-plugin-types.h
@@ -188,6 +188,7 @@ typedef enum {
  * GsPluginRefineCategoriesFlags:
  * @GS_PLUGIN_REFINE_CATEGORIES_FLAGS_NONE: No flags set.
  * @GS_PLUGIN_REFINE_CATEGORIES_FLAGS_INTERACTIVE: User initiated the job.
+ * @GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE: Work out the number of apps in each category.
  *
  * Flags for an operation to refine categories.
  *
@@ -196,6 +197,7 @@ typedef enum {
 typedef enum {
        GS_PLUGIN_REFINE_CATEGORIES_FLAGS_NONE = 0,
        GS_PLUGIN_REFINE_CATEGORIES_FLAGS_INTERACTIVE = 1 << 0,
+       GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE = 1 << 1,
 } GsPluginRefineCategoriesFlags;
 
 /**
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index d6ff5f29d..36ebca9e8 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -1356,6 +1356,13 @@ gs_plugin_appstream_refine_categories_async (GsPlugin                      *plug
                                                          cancellable, callback, user_data);
        g_task_set_source_tag (task, gs_plugin_appstream_refine_categories_async);
 
+       /* All we actually do is add the sizes of each category. If that’s
+        * not been requested, avoid queueing a worker job. */
+       if (!(flags & GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE)) {
+               g_task_return_boolean (task, TRUE);
+               return;
+       }
+
        /* Queue a job to get the apps. */
        gs_worker_thread_queue (self->worker, get_priority_for_interactivity (interactive),
                                refine_categories_thread_cb, g_steal_pointer (&task));
@@ -1383,7 +1390,7 @@ refine_categories_thread_cb (GTask        *task,
 
        locker = g_rw_lock_reader_locker_new (&self->silo_lock);
 
-       if (!gs_appstream_add_categories (self->silo, data->list, cancellable, &local_error)) {
+       if (!gs_appstream_refine_category_sizes (self->silo, data->list, cancellable, &local_error)) {
                g_task_return_error (task, g_steal_pointer (&local_error));
                return;
        }
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 4df7c8cd5..6f1a391be 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -4281,19 +4281,18 @@ gs_flatpak_add_category_apps (GsFlatpak *self,
 }
 
 gboolean
-gs_flatpak_add_categories (GsFlatpak *self,
-                          GPtrArray *list,
-                          gboolean interactive,
-                          GCancellable *cancellable,
-                          GError **error)
+gs_flatpak_refine_category_sizes (GsFlatpak     *self,
+                                  GPtrArray     *list,
+                                  gboolean       interactive,
+                                  GCancellable  *cancellable,
+                                  GError       **error)
 {
        g_autoptr(GRWLockReaderLocker) locker = NULL;
 
        if (!ensure_flatpak_silo_with_locker (self, &locker, interactive, cancellable, error))
                return FALSE;
 
-       return gs_appstream_add_categories (self->silo,
-                                           list, cancellable, error);
+       return gs_appstream_refine_category_sizes (self->silo, list, cancellable, error);
 }
 
 gboolean
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index c2de7fceb..b3f8a13b2 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -131,7 +131,7 @@ gboolean    gs_flatpak_search_developer_apps(GsFlatpak              *self,
                                                 gboolean                interactive,
                                                 GCancellable           *cancellable,
                                                 GError                 **error);
-gboolean       gs_flatpak_add_categories       (GsFlatpak              *self,
+gboolean       gs_flatpak_refine_category_sizes(GsFlatpak              *self,
                                                 GPtrArray              *list,
                                                 gboolean                interactive,
                                                 GCancellable           *cancellable,
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 45a0c979f..f5bc68569 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -1770,6 +1770,13 @@ gs_plugin_flatpak_refine_categories_async (GsPlugin                      *plugin
                                                          cancellable, callback, user_data);
        g_task_set_source_tag (task, gs_plugin_flatpak_refine_categories_async);
 
+       /* All we actually do is add the sizes of each category. If that’s
+        * not been requested, avoid queueing a worker job. */
+       if (!(flags & GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE)) {
+               g_task_return_boolean (task, TRUE);
+               return;
+       }
+
        /* Queue a job to get the apps. */
        gs_worker_thread_queue (self->worker, get_priority_for_interactivity (interactive),
                                refine_categories_thread_cb, g_steal_pointer (&task));
@@ -1793,7 +1800,7 @@ refine_categories_thread_cb (GTask        *task,
        for (guint i = 0; i < self->installations->len; i++) {
                GsFlatpak *flatpak = g_ptr_array_index (self->installations, i);
 
-               if (!gs_flatpak_add_categories (flatpak, data->list, interactive, cancellable, &local_error)) 
{
+               if (!gs_flatpak_refine_category_sizes (flatpak, data->list, interactive, cancellable, 
&local_error)) {
                        g_task_return_error (task, g_steal_pointer (&local_error));
                        return;
                }
diff --git a/src/gs-overview-page.c b/src/gs-overview-page.c
index 2554c6dfe..b9fd8c338 100644
--- a/src/gs-overview-page.c
+++ b/src/gs-overview-page.c
@@ -760,7 +760,8 @@ gs_overview_page_load (GsOverviewPage *self)
 
        if (!self->loading_categories) {
                g_autoptr(GsPluginJob) plugin_job = NULL;
-               GsPluginRefineCategoriesFlags flags = GS_PLUGIN_REFINE_CATEGORIES_FLAGS_INTERACTIVE;
+               GsPluginRefineCategoriesFlags flags = GS_PLUGIN_REFINE_CATEGORIES_FLAGS_INTERACTIVE |
+                                                     GS_PLUGIN_REFINE_CATEGORIES_FLAGS_SIZE;
                g_autoptr(GetCategoriesData) data = NULL;
 
                self->loading_categories = TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]