[gnome-software: 17/20] fedora-pkgdb-collections: Avoid refreshing the collections early




commit bda25c539723d899cf8d33243aa46410b3b6a05f
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Mar 11 13:37:33 2022 +0000

    fedora-pkgdb-collections: Avoid refreshing the collections early
    
    During early startup of gnome-software, refresh-metadata is called, and
    then refine is potentially called on the `install-queue` (if it exists).
    
    refresh-metadata will start refreshing the cache, which will create the
    existing cache file to be empty if it doesn’t already exist. If the
    refine job is then run before the refresh has completed, it will end up
    loading the empty cache file and then erroring out as it fails to parse
    it.
    
    Given that the refine job is part of setup, the error will then
    propagate and cause setup to fail.
    
    Work around that by avoiding refreshing the cache if the refine job
    isn’t relevant to any OS updates (which it’s unlikely to be in any
    case). This works around the issue, but is also correct in its own
    right, as it spreads work out over time rather than causing it to all be
    done immediately at startup.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1670

 .../gs-plugin-fedora-pkgdb-collections.c                | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
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 965bdc595..bdafea58b 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -760,11 +760,28 @@ gs_plugin_fedora_pkgdb_collections_refine_async (GsPlugin            *plugin,
 {
        GsPluginFedoraPkgdbCollections *self = GS_PLUGIN_FEDORA_PKGDB_COLLECTIONS (plugin);
        g_autoptr(GTask) task = NULL;
+       gboolean refine_needed = FALSE;
        g_autoptr(GError) local_error = NULL;
 
        task = gs_plugin_refine_data_new_task (plugin, list, flags, cancellable, callback, user_data);
        g_task_set_source_tag (task, gs_plugin_fedora_pkgdb_collections_refine_async);
 
+       /* Check if any of the apps actually need to be refined by this plugin,
+        * before potentially updating the collections file from the internet. */
+       for (guint i = 0; i < gs_app_list_length (list); i++) {
+               GsApp *app = gs_app_list_index (list, i);
+
+               if (gs_app_get_kind (app) == AS_COMPONENT_KIND_OPERATING_SYSTEM) {
+                       refine_needed = TRUE;
+                       break;
+               }
+       }
+
+       if (!refine_needed) {
+               g_task_return_boolean (task, TRUE);
+               return;
+       }
+
        /* ensure valid data is loaded */
        _ensure_cache_async (self, cancellable, refine_cb, g_steal_pointer (&task));
 }


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