[gnome-software: 4/72] appstream: Make refine asynchronous
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 4/72] appstream: Make refine asynchronous
- Date: Wed, 15 Dec 2021 13:00:54 +0000 (UTC)
commit 0d7d5cda6dc24ed7c2af81675c30a239e050ae4d
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Nov 24 16:26:31 2021 +0000
appstream: Make refine asynchronous
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
plugins/core/gs-plugin-appstream.c | 72 +++++++++++++++++++++++++++++++-------
1 file changed, 59 insertions(+), 13 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 2998cd84a..ac82b42df 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -1012,19 +1012,51 @@ gs_plugin_refine_from_pkgname (GsPluginAppstream *self,
return TRUE;
}
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GsAppList *list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static void refine_thread_cb (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable);
+
+static void
+gs_plugin_appstream_refine_async (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GsPluginAppstream *self = GS_PLUGIN_APPSTREAM (plugin);
+ g_autoptr(GTask) task = NULL;
+
+ task = gs_plugin_refine_data_new_task (plugin, list, flags, cancellable, callback, user_data);
+ g_task_set_source_tag (task, gs_plugin_appstream_refine_async);
+
+ /* Queue a job for the refine. */
+ gs_worker_thread_queue (self->worker, G_PRIORITY_DEFAULT,
+ refine_thread_cb, g_steal_pointer (&task));
+}
+
+/* Run in @worker. */
+static void
+refine_thread_cb (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GsPluginAppstream *self = GS_PLUGIN_APPSTREAM (source_object);
+ GsPluginRefineData *data = task_data;
+ GsAppList *list = data->list;
+ GsPluginRefineFlags flags = data->flags;
gboolean found = FALSE;
+ g_autoptr(GError) local_error = NULL;
+
+ assert_in_worker (self);
/* check silo is valid */
- if (!gs_plugin_appstream_check_silo (self, cancellable, error))
- return FALSE;
+ if (!gs_plugin_appstream_check_silo (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);
@@ -1035,16 +1067,28 @@ gs_plugin_refine (GsPlugin *plugin,
continue;
/* find by ID then fall back to package name */
- if (!gs_plugin_refine_from_id (self, app, flags, &found, error))
- return FALSE;
+ if (!gs_plugin_refine_from_id (self, app, flags, &found, &local_error)) {
+ g_task_return_error (task, g_steal_pointer (&local_error));
+ return;
+ }
if (!found) {
- if (!gs_plugin_refine_from_pkgname (self, app, flags, error))
- return FALSE;
+ if (!gs_plugin_refine_from_pkgname (self, app, flags, &local_error)) {
+ g_task_return_error (task, g_steal_pointer (&local_error));
+ return;
+ }
}
}
/* success */
- return TRUE;
+ g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+gs_plugin_appstream_refine_finish (GsPlugin *plugin,
+ GAsyncResult *result,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (result), error);
}
gboolean
@@ -1289,6 +1333,8 @@ gs_plugin_appstream_class_init (GsPluginAppstreamClass *klass)
plugin_class->setup_finish = gs_plugin_appstream_setup_finish;
plugin_class->shutdown_async = gs_plugin_appstream_shutdown_async;
plugin_class->shutdown_finish = gs_plugin_appstream_shutdown_finish;
+ plugin_class->refine_async = gs_plugin_appstream_refine_async;
+ plugin_class->refine_finish = gs_plugin_appstream_refine_finish;
}
GType
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]