[gnome-software/mwleeds/fix-deprecated-install: 109/110] flatpak: Get size info more efficiently




commit ae85ec455329a6ebc2318e42156a71ff76490c10
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Wed Nov 3 12:57:10 2021 -0700

    flatpak: Get size info more efficiently
    
    We should use the download and installed size information if it's
    available in gs_flatpak_set_metadata(), because otherwise we're going to
    have to fetch the info again in gs_plugin_refine_item_size() later on,
    which is inefficient.

 plugins/flatpak/gs-flatpak.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index a2148adc1..2ebe2a08d 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -310,6 +310,7 @@ static void
 gs_flatpak_set_metadata (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
 {
        g_autofree gchar *ref_tmp = flatpak_ref_format_ref (FLATPAK_REF (xref));
+       guint64 installed_size = 0, download_size = 0;
 
        /* core */
        gs_flatpak_claim_app (self, app);
@@ -333,6 +334,17 @@ gs_flatpak_set_metadata (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
                gs_app_set_metadata (app, "GnomeSoftware::EolReason", flatpak_remote_ref_get_eol 
(FLATPAK_REMOTE_REF (xref)));
        else if (FLATPAK_IS_INSTALLED_REF (xref) && flatpak_installed_ref_get_eol (FLATPAK_INSTALLED_REF 
(xref)) != NULL)
                gs_app_set_metadata (app, "GnomeSoftware::EolReason", flatpak_installed_ref_get_eol 
(FLATPAK_INSTALLED_REF (xref)));
+
+       if (FLATPAK_IS_REMOTE_REF (xref)) {
+               installed_size = flatpak_remote_ref_get_installed_size (FLATPAK_REMOTE_REF (xref));
+               download_size = flatpak_remote_ref_get_download_size (FLATPAK_REMOTE_REF (xref));
+       } else if (FLATPAK_IS_INSTALLED_REF (xref)) {
+               installed_size = flatpak_installed_ref_get_installed_size (FLATPAK_INSTALLED_REF (xref));
+       }
+       if (installed_size != 0)
+               gs_app_set_size_installed (app, installed_size);
+       if (download_size != 0)
+               gs_app_set_size_download (app, download_size);
 }
 
 static GsApp *


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