[gnome-software/wip/kalev/download-step: 3/3] packagekit refresh: Avoid re-downloading metadata for gs_plugin_download()



commit ce2942b306e79f3d84cb201f699f929e13d0b2f1
Author: Kalev Lember <klember redhat com>
Date:   Wed Oct 24 08:18:06 2018 +0200

    packagekit refresh: Avoid re-downloading metadata for gs_plugin_download()
    
    When we get the list of updates with pk_client_get_updates in
    download(), the side effect is that it also goes and re-downloads
    metadata, depending on the cache age. This is costly, both time wise and
    network IO wise. It should also be unnecessary to re-download the
    metadata as the frontend always calls refresh() before, ensuring up to
    date metadata.
    
    In addition, the metadata download in gs_plugin_download() right now
    shows up in the UI as a stuck progress bar at 0%, as we only report
    package download progress (gs_app_list progress) up to the UI, not
    metadata progress.
    
    As a fix, this bumps the cache age up to max for the
    pk_client_get_updates call, so that it just uses the same metadata that
    refresh() downloaded.
    
    Avoiding the metadata re-download also hopefully makes it less likely
    that the things shown in the UI in the updates panel, and the actual
    metadata used for the downloads goes out of sync and we download
    something that we didn't show to the user before.

 plugins/packagekit/gs-plugin-packagekit-refresh.c | 5 +++++
 1 file changed, 5 insertions(+)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit-refresh.c 
b/plugins/packagekit/gs-plugin-packagekit-refresh.c
index 1383ba0b..e2660127 100644
--- a/plugins/packagekit/gs-plugin-packagekit-refresh.c
+++ b/plugins/packagekit/gs-plugin-packagekit-refresh.c
@@ -62,6 +62,7 @@ _download_only (GsPlugin *plugin, GsAppList *list,
                GCancellable *cancellable, GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       guint cache_age_save;
        g_auto(GStrv) package_ids = NULL;
        g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
        g_autoptr(PkPackageSack) sack = NULL;
@@ -70,11 +71,15 @@ _download_only (GsPlugin *plugin, GsAppList *list,
 
        /* refresh the metadata */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
+       cache_age_save = pk_client_get_cache_age (PK_CLIENT (priv->task));
+       pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
        results = pk_client_get_updates (PK_CLIENT (priv->task),
                                         pk_bitfield_value (PK_FILTER_ENUM_NONE),
                                         cancellable,
                                         gs_packagekit_helper_cb, helper,
                                         error);
+       pk_client_set_cache_age (PK_CLIENT (priv->task), cache_age_save);
+
        if (!gs_plugin_packagekit_results_valid (results, error)) {
                g_prefix_error (error, "failed to get updates for refresh: ");
                return FALSE;


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