[gnome-software/gnome-3-34] flatpak: Cache installed refs for an installation



commit a96e3139e9ba2ef9b29a72196de916dc71d78b16
Author: Andre Moreira Magalhaes <andre endlessm com>
Date:   Tue Nov 5 21:28:12 2019 -0300

    flatpak: Cache installed refs for an installation
    
    This improves the performance substantially during loading.
    
    https://phabricator.endlessm.com/T28503

 plugins/flatpak/gs-flatpak.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index f9993cc1..e86ac4bc 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -27,6 +27,7 @@ struct _GsFlatpak {
        GObject                  parent_instance;
        GsFlatpakFlags           flags;
        FlatpakInstallation     *installation;
+       GPtrArray               *installed_refs;
        GHashTable              *broken_remotes;
        GMutex                   broken_remotes_mutex;
        GFileMonitor            *monitor;
@@ -301,6 +302,9 @@ gs_plugin_flatpak_changed_cb (GFileMonitor *monitor,
                g_warning ("failed to drop cache: %s", error->message);
                return;
        }
+
+       /* drop the installed refs cache */
+       g_clear_pointer (&self->installed_refs, g_ptr_array_unref);
 }
 
 static gboolean
@@ -1486,6 +1490,9 @@ gs_flatpak_refresh (GsFlatpak *self,
                return FALSE;
        }
 
+       /* drop the installed refs cache */
+       g_clear_pointer (&self->installed_refs, g_ptr_array_unref);
+
        /* manually do this in case we created the first appstream file */
        g_rw_lock_reader_lock (&self->silo_lock);
        if (self->silo != NULL)
@@ -1689,7 +1696,6 @@ gs_flatpak_refine_app_state_unlocked (GsFlatpak *self,
                                       GError **error)
 {
        g_autoptr(FlatpakInstalledRef) ref = NULL;
-       g_autoptr(GPtrArray) refs = NULL;
 
        /* already found */
        if (gs_app_get_state (app) != AS_APP_STATE_UNKNOWN)
@@ -1700,14 +1706,17 @@ gs_flatpak_refine_app_state_unlocked (GsFlatpak *self,
                return FALSE;
 
        /* find the app using the origin and the ID */
-       refs = flatpak_installation_list_installed_refs (self->installation,
-                                                        cancellable, error);
-       if (refs == NULL) {
+       if (self->installed_refs == NULL) {
+               self->installed_refs = flatpak_installation_list_installed_refs (self->installation,
+                                                                cancellable, error);
+       }
+
+       if (self->installed_refs == NULL) {
                gs_flatpak_error_convert (error);
                return FALSE;
        }
-       for (guint i = 0; i < refs->len; i++) {
-               FlatpakInstalledRef *ref_tmp = g_ptr_array_index (refs, i);
+       for (guint i = 0; i < self->installed_refs->len; i++) {
+               FlatpakInstalledRef *ref_tmp = g_ptr_array_index (self->installed_refs, i);
                const gchar *origin = flatpak_installed_ref_get_origin (ref_tmp);
                const gchar *name = flatpak_ref_get_name (FLATPAK_REF (ref_tmp));
                const gchar *arch = flatpak_ref_get_arch (FLATPAK_REF (ref_tmp));
@@ -2947,6 +2956,7 @@ gs_flatpak_finalize (GObject *object)
 
        g_free (self->id);
        g_object_unref (self->installation);
+       g_clear_pointer (&self->installed_refs, g_ptr_array_unref);
        g_object_unref (self->plugin);
        g_hash_table_unref (self->broken_remotes);
        g_mutex_clear (&self->broken_remotes_mutex);


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