[gnome-builder] flatpak: avoid loading properties at construction



commit cf6b4c17686022155ec3177453f7c7d67839bf3c
Author: Christian Hergert <chergert redhat com>
Date:   Mon Dec 13 16:01:25 2021 -0800

    flatpak: avoid loading properties at construction
    
    If we create the proxy synchronously, we end up blocking on waiting for
    properties to load. That has the side-effect of blocking until the
    repository setup work in the gnome-builder-flatpak daemon has completed.
    
    Instead, we can create the proxy asynchronously and just delay IdeTask
    completion until the async proxy has completed loading. Future tasks will
    automatically queue behind that operation completing.

 src/plugins/flatpak/gbp-flatpak-client.c | 94 ++++++++++++++++++++++----------
 1 file changed, 65 insertions(+), 29 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-client.c b/src/plugins/flatpak/gbp-flatpak-client.c
index e2adc4a3d..b66c56749 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.c
+++ b/src/plugins/flatpak/gbp-flatpak-client.c
@@ -142,47 +142,47 @@ handle_error:
 }
 
 static void
-gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
-                                       IdeSubprocess           *subprocess,
-                                       IdeSubprocessSupervisor *supervisor)
+gbp_flatpak_client_proxy_created_cb (GObject      *object,
+                                     GAsyncResult *result,
+                                     gpointer      user_data)
 {
-  g_autofree gchar *home_install = NULL;
+  g_autoptr(GbpFlatpakClient) self = user_data;
+  g_autoptr(IpcFlatpakService) service = NULL;
+  g_autoptr(GError) error = NULL;
   GList *queued;
 
   IDE_ENTRY;
 
   g_assert (GBP_IS_FLATPAK_CLIENT (self));
-  g_assert (IDE_IS_SUBPROCESS (subprocess));
-  g_assert (IDE_IS_SUBPROCESS_SUPERVISOR (supervisor));
+  g_assert (G_IS_ASYNC_RESULT (result));
 
   g_mutex_lock (&self->mutex);
 
-  g_assert (self->service == NULL);
-  g_assert (self->connection != NULL);
-
-  ide_subprocess_supervisor_set_launcher (self->supervisor, NULL);
+  if ((service = ipc_flatpak_service_proxy_new_finish (result, &error)))
+    {
+      g_autofree char *home_install = NULL;
+
+      /* We can have long running operations, so set no timeout */
+      g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (service), G_MAXINT);
+
+      /* Add the --user installation as our first call before queued
+       * events can submit their operations.
+       */
+      home_install = g_build_filename (g_get_home_dir (),
+                                       ".local",
+                                       "share",
+                                       "flatpak",
+                                       NULL);
+      if (g_file_test (home_install, G_FILE_TEST_IS_DIR))
+        ipc_flatpak_service_call_add_installation (service, home_install, TRUE, NULL, NULL, NULL);
+    }
 
-  if (self->state == STATE_SPAWNING)
+  if (self->state == STATE_SPAWNING && service != NULL)
     self->state = STATE_RUNNING;
 
-  g_dbus_connection_start_message_processing (self->connection);
-
-  self->service = ipc_flatpak_service_proxy_new_sync (self->connection,
-                                                      G_DBUS_PROXY_FLAGS_NONE,
-                                                      NULL,
-                                                      "/org/gnome/Builder/Flatpak",
-                                                      NULL,
-                                                      NULL);
-
-  /* We can have long running operations, so set no timeout */
-  g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (self->service), G_MAXINT);
+  g_assert (error != NULL || service != NULL);
 
-  /* Add the --user installation as our first call before queued
-   * events can submit their operations.
-   */
-  home_install = g_build_filename (g_get_home_dir (), ".local", "share", "flatpak", NULL);
-  if (g_file_test (home_install, G_FILE_TEST_IS_DIR))
-    ipc_flatpak_service_call_add_installation (self->service, home_install, TRUE, NULL, NULL, NULL);
+  g_set_object (&self->service, service);
 
   queued = g_steal_pointer (&self->get_service.head);
 
@@ -194,7 +194,10 @@ gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
     {
       IdeTask *task = iter->data;
 
-      ide_task_return_object (task, g_object_ref (self->service));
+      if (error)
+        ide_task_return_error (task, g_error_copy (error));
+      else
+        ide_task_return_object (task, g_object_ref (self->service));
     }
 
   g_list_free_full (queued, g_object_unref);
@@ -204,6 +207,39 @@ gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
   IDE_EXIT;
 }
 
+static void
+gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
+                                       IdeSubprocess           *subprocess,
+                                       IdeSubprocessSupervisor *supervisor)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_CLIENT (self));
+  g_assert (IDE_IS_SUBPROCESS (subprocess));
+  g_assert (IDE_IS_SUBPROCESS_SUPERVISOR (supervisor));
+
+  g_mutex_lock (&self->mutex);
+
+  g_assert (self->service == NULL);
+  g_assert (self->connection != NULL);
+
+  ide_subprocess_supervisor_set_launcher (self->supervisor, NULL);
+
+  ipc_flatpak_service_proxy_new (self->connection,
+                                 G_DBUS_PROXY_FLAGS_NONE,
+                                 NULL,
+                                 "/org/gnome/Builder/Flatpak",
+                                 NULL,
+                                 gbp_flatpak_client_proxy_created_cb,
+                                 g_object_ref (self));
+
+  g_dbus_connection_start_message_processing (self->connection);
+
+  g_mutex_unlock (&self->mutex);
+
+  IDE_EXIT;
+}
+
 static void
 gbp_flatpak_client_subprocess_exited (GbpFlatpakClient        *self,
                                       IdeSubprocess           *subprocess,


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