[gnome-software/mwleeds/hardcoded-pwa-list: 5/6] gs-plugin-job-list-installed-apps: Respect plugin order




commit e6c97896426d7f829d9189b6dc1ec71228ae3789
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Tue Mar 22 15:45:02 2022 -0700

    gs-plugin-job-list-installed-apps: Respect plugin order
    
    This is important at least for the epiphany plugin, which needs the
    appstream plugin to have already run its list_installed_apps_async()
    vfunc before that vfunc is run on the epiphany plugin. This matches what
    we do for GsPluginJobRefine.

 lib/gs-plugin-job-list-installed-apps.c | 47 +++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
---
diff --git a/lib/gs-plugin-job-list-installed-apps.c b/lib/gs-plugin-job-list-installed-apps.c
index 4bce8f9a4..3fd229ccf 100644
--- a/lib/gs-plugin-job-list-installed-apps.c
+++ b/lib/gs-plugin-job-list-installed-apps.c
@@ -63,6 +63,7 @@ struct _GsPluginJobListInstalledApps
        GsAppList *merged_list;  /* (owned) (nullable) */
        GError *saved_error;  /* (owned) (nullable) */
        guint n_pending_ops;
+       guint current_batch;
 
        /* Results. */
        GsAppList *result_list;  /* (owned) (nullable) */
@@ -281,12 +282,14 @@ gs_plugin_job_list_installed_apps_run_async (GsPluginJob         *job,
        /* run each plugin, keeping a counter of pending operations which is
         * initialised to 1 until all the operations are started */
        self->n_pending_ops = 1;
+       self->current_batch = G_MAXUINT;
        self->merged_list = gs_app_list_new ();
        plugins = gs_plugin_loader_get_plugins (plugin_loader);
 
        for (guint i = 0; i < plugins->len; i++) {
                GsPlugin *plugin = g_ptr_array_index (plugins, i);
                GsPluginClass *plugin_class = GS_PLUGIN_GET_CLASS (plugin);
+               guint plugin_order = gs_plugin_get_order (plugin);
 
                if (!gs_plugin_get_enabled (plugin))
                        continue;
@@ -296,6 +299,11 @@ gs_plugin_job_list_installed_apps_run_async (GsPluginJob         *job,
                /* at least one plugin supports this vfunc */
                anything_ran = TRUE;
 
+               if (self->current_batch == G_MAXUINT)
+                       self->current_batch = plugin_order;
+               else if (self->current_batch != plugin_order)
+                       break;
+
                /* run the plugin */
                self->n_pending_ops++;
                plugin_class->list_installed_apps_async (plugin, self->flags,
@@ -346,8 +354,10 @@ finish_op (GTask  *task,
        GsPluginJobListInstalledApps *self = g_task_get_source_object (task);
        GCancellable *cancellable = g_task_get_cancellable (task);
        GsPluginLoader *plugin_loader = g_task_get_task_data (task);
+       GPtrArray *plugins;  /* (element-type GsPlugin) */
        g_autoptr(GsAppList) merged_list = NULL;
        g_autoptr(GError) error_owned = g_steal_pointer (&error);
+       guint prev_batch = self->current_batch;
 
        if (error_owned != NULL && self->saved_error == NULL)
                self->saved_error = g_steal_pointer (&error_owned);
@@ -357,6 +367,43 @@ finish_op (GTask  *task,
        g_assert (self->n_pending_ops > 0);
        self->n_pending_ops--;
 
+       if (self->n_pending_ops > 0)
+               return;
+
+       self->n_pending_ops = 1; /* increment while starting the batch */
+       self->current_batch = G_MAXUINT;
+       plugins = gs_plugin_loader_get_plugins (plugin_loader);
+
+       /* Check if there's another batch of plugins to run */
+       for (guint i = 0; i < plugins->len; i++) {
+               GsPlugin *plugin = g_ptr_array_index (plugins, i);
+               GsPluginClass *plugin_class = GS_PLUGIN_GET_CLASS (plugin);
+               guint plugin_order = gs_plugin_get_order (plugin);
+
+               if (!gs_plugin_get_enabled (plugin))
+                       continue;
+               if (plugin_class->list_installed_apps_async == NULL)
+                       continue;
+
+               if (plugin_order <= prev_batch)
+                       continue;
+
+               if (self->current_batch == G_MAXUINT)
+                       self->current_batch = plugin_order;
+               else if (plugin_order > self->current_batch)
+                       break;
+
+               /* run the plugin */
+               self->n_pending_ops++;
+               plugin_class->list_installed_apps_async (plugin, self->flags,
+                                                        cancellable,
+                                                        plugin_list_installed_apps_cb,
+                                                        g_object_ref (task));
+       }
+
+       g_assert (self->n_pending_ops > 0);
+       self->n_pending_ops--;
+
        if (self->n_pending_ops > 0)
                return;
 


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