[gnome-software: 31/72] fedora-pkgdb-collections: Make refine asynchronous




commit 118efe3d1baf11ed0610a2a222016ca02b3de0d1
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Nov 24 17:13:56 2021 +0000

    fedora-pkgdb-collections: Make refine asynchronous
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 .../gs-plugin-fedora-pkgdb-collections.c           | 43 ++++++++++++++++------
 1 file changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 30ab2b94c..20053f4d5 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -443,6 +443,7 @@ _ensure_cache (GsPluginFedoraPkgdbCollections  *self,
                return TRUE;
 
        /* just ensure there is any data, no matter how old */
+       /* FIXME: This can download from the network, so needs to be made async */
        if (!_refresh_cache (self, G_MAXUINT, cancellable, error))
                return FALSE;
 
@@ -634,27 +635,45 @@ refine_app_locked (GsPluginFedoraPkgdbCollections  *self,
        return TRUE;
 }
 
-gboolean
-gs_plugin_refine (GsPlugin             *plugin,
-                 GsAppList            *list,
-                 GsPluginRefineFlags   flags,
-                 GCancellable         *cancellable,
-                 GError              **error)
+static void
+gs_plugin_fedora_pkgdb_collections_refine_async (GsPlugin            *plugin,
+                                                 GsAppList           *list,
+                                                 GsPluginRefineFlags  flags,
+                                                 GCancellable        *cancellable,
+                                                 GAsyncReadyCallback  callback,
+                                                 gpointer             user_data)
 {
        GsPluginFedoraPkgdbCollections *self = GS_PLUGIN_FEDORA_PKGDB_COLLECTIONS (plugin);
        g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&self->mutex);
+       g_autoptr(GTask) task = NULL;
+       g_autoptr(GError) local_error = NULL;
+
+       task = g_task_new (plugin, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gs_plugin_fedora_pkgdb_collections_refine_async);
 
        /* ensure valid data is loaded */
-       if (!_ensure_cache (self, cancellable, error))
-               return FALSE;
+       if (!_ensure_cache (self, cancellable, &local_error)) {
+               g_task_return_error (task, g_steal_pointer (&local_error));
+               return;
+       }
 
        for (guint i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               if (!refine_app_locked (self, app, flags, cancellable, error))
-                       return FALSE;
+               if (!refine_app_locked (self, app, flags, cancellable, &local_error)) {
+                       g_task_return_error (task, g_steal_pointer (&local_error));
+                       return;
+               }
        }
 
-       return TRUE;
+       g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+gs_plugin_fedora_pkgdb_collections_refine_finish (GsPlugin      *plugin,
+                                                  GAsyncResult  *result,
+                                                  GError       **error)
+{
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
@@ -668,6 +687,8 @@ gs_plugin_fedora_pkgdb_collections_class_init (GsPluginFedoraPkgdbCollectionsCla
 
        plugin_class->setup_async = gs_plugin_fedora_pkgdb_collections_setup_async;
        plugin_class->setup_finish = gs_plugin_fedora_pkgdb_collections_setup_finish;
+       plugin_class->refine_async = gs_plugin_fedora_pkgdb_collections_refine_async;
+       plugin_class->refine_finish = gs_plugin_fedora_pkgdb_collections_refine_finish;
 }
 
 GType


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