[gnome-software] Do not re-request data from the PluginLoader if we can use cached data



commit fd961af6edd2db6b8d3a0413aece57b548152d0f
Author: Richard Hughes <richard hughsie com>
Date:   Thu Aug 22 13:28:01 2013 +0100

    Do not re-request data from the PluginLoader if we can use cached data

 src/gs-shell-installed.c |   15 +++++++++++++++
 src/gs-shell-installed.h |    1 +
 src/gs-shell-overview.c  |   15 +++++++++++++++
 src/gs-shell-overview.h  |    1 +
 src/gs-shell-updates.c   |   16 ++++++++++++++++
 src/gs-shell-updates.h   |    1 +
 src/gs-shell.h           |    2 ++
 7 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index b79d4fd..238170c 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -39,11 +39,21 @@ struct GsShellInstalledPrivate
        GtkListBox              *list_box_installed;
        GtkSizeGroup            *sizegroup_image;
        GtkSizeGroup            *sizegroup_name;
+       gboolean                 cache_valid;
 };
 
 G_DEFINE_TYPE (GsShellInstalled, gs_shell_installed, G_TYPE_OBJECT)
 
 /**
+ * gs_shell_installed_invalidate:
+ **/
+void
+gs_shell_installed_invalidate (GsShellInstalled *shell_installed)
+{
+       shell_installed->priv->cache_valid = FALSE;
+}
+
+/**
  * _gtk_container_remove_all_cb:
  **/
 static void
@@ -203,6 +213,10 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed,
 {
        GsShellInstalledPrivate *priv = shell_installed->priv;
 
+       /* no need to refresh */
+       if (priv->cache_valid)
+               return;
+
        /* remove old entries */
        _gtk_container_remove_all (GTK_CONTAINER (priv->list_box_installed));
 
@@ -211,6 +225,7 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed,
                                              cancellable,
                                              gs_shell_installed_get_installed_cb,
                                              shell_installed);
+       priv->cache_valid = TRUE;
 }
 
 /**
diff --git a/src/gs-shell-installed.h b/src/gs-shell-installed.h
index a1bbb44..9de429e 100644
--- a/src/gs-shell-installed.h
+++ b/src/gs-shell-installed.h
@@ -52,6 +52,7 @@ typedef struct
 GType           gs_shell_installed_get_type    (void);
 
 GsShellInstalled *gs_shell_installed_new       (void);
+void            gs_shell_installed_invalidate  (GsShellInstalled       *shell_installed);
 void            gs_shell_installed_refresh     (GsShellInstalled       *shell_installed,
                                                 GCancellable           *cancellable);
 void            gs_shell_installed_setup       (GsShellInstalled       *shell_installed,
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index bee0f6c..e88e879 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -34,6 +34,7 @@ struct GsShellOverviewPrivate
 {
        GsPluginLoader          *plugin_loader;
        GtkBuilder              *builder;
+       gboolean                 cache_valid;
 };
 
 enum {
@@ -45,6 +46,15 @@ G_DEFINE_TYPE (GsShellOverview, gs_shell_overview, G_TYPE_OBJECT)
 
 static guint signals [SIGNAL_LAST] = { 0 };
 
+/**
+ * gs_shell_overview_invalidate:
+ **/
+void
+gs_shell_overview_invalidate (GsShellOverview *shell_overview)
+{
+       shell_overview->priv->cache_valid = FALSE;
+}
+
 static void
 container_remove_all (GtkContainer *container)
 {
@@ -419,6 +429,10 @@ gs_shell_overview_refresh (GsShellOverview *shell_overview, GCancellable *cancel
        guint i;
        GtkWidget *tile;
 
+       /* no need to refresh */
+       if (priv->cache_valid)
+               return;
+
        grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "grid_categories"));
        container_remove_all (GTK_CONTAINER (grid));
 
@@ -441,6 +455,7 @@ gs_shell_overview_refresh (GsShellOverview *shell_overview, GCancellable *cancel
                                             cancellable,
                                             gs_shell_overview_get_featured_cb,
                                             shell_overview);
+       priv->cache_valid = TRUE;
 }
 
 /**
diff --git a/src/gs-shell-overview.h b/src/gs-shell-overview.h
index dc6f198..37bf841 100644
--- a/src/gs-shell-overview.h
+++ b/src/gs-shell-overview.h
@@ -56,6 +56,7 @@ typedef struct
 GType           gs_shell_overview_get_type     (void);
 
 GsShellOverview        *gs_shell_overview_new          (void);
+void            gs_shell_overview_invalidate   (GsShellOverview        *shell_overview);
 void            gs_shell_overview_refresh      (GsShellOverview        *shell_overview,
                                                 GCancellable           *cancellable);
 void            gs_shell_overview_setup        (GsShellOverview        *shell_overview,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index e01c32d..3dd0bb9 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -35,6 +35,7 @@ struct GsShellUpdatesPrivate
        GsPluginLoader          *plugin_loader;
        GtkBuilder              *builder;
        GtkListBox              *list_box_updates;
+       gboolean                 cache_valid;
 };
 
 enum {
@@ -47,6 +48,15 @@ enum {
 G_DEFINE_TYPE (GsShellUpdates, gs_shell_updates, G_TYPE_OBJECT)
 
 /**
+ * gs_shell_updates_invalidate:
+ **/
+void
+gs_shell_updates_invalidate (GsShellUpdates *shell_updates)
+{
+       shell_updates->priv->cache_valid = FALSE;
+}
+
+/**
  * _gtk_container_remove_all_cb:
  **/
 static void
@@ -123,11 +133,17 @@ void
 gs_shell_updates_refresh (GsShellUpdates *shell_updates, GCancellable *cancellable)
 {
        GsShellUpdatesPrivate *priv = shell_updates->priv;
+
+       /* no need to refresh */
+       if (priv->cache_valid)
+               return;
+
        _gtk_container_remove_all (GTK_CONTAINER (priv->list_box_updates));
        gs_plugin_loader_get_updates_async (priv->plugin_loader,
                                            cancellable,
                                            (GAsyncReadyCallback) gs_shell_updates_get_updates_cb,
                                            shell_updates);
+       priv->cache_valid = TRUE;
 }
 
 /**
diff --git a/src/gs-shell-updates.h b/src/gs-shell-updates.h
index da5e370..859976b 100644
--- a/src/gs-shell-updates.h
+++ b/src/gs-shell-updates.h
@@ -52,6 +52,7 @@ typedef struct
 GType           gs_shell_updates_get_type      (void);
 
 GsShellUpdates *gs_shell_updates_new           (void);
+void            gs_shell_updates_invalidate    (GsShellUpdates         *shell_updates);
 void            gs_shell_updates_refresh       (GsShellUpdates         *shell_updates,
                                                 GCancellable           *cancellable);
 void            gs_shell_updates_setup         (GsShellUpdates         *shell_updates,
diff --git a/src/gs-shell.h b/src/gs-shell.h
index fea5391..df07f6d 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -69,5 +69,7 @@ void           gs_shell_set_default_mode      (GsShell        *shell,
 GtkWindow      *gs_shell_setup                 (GsShell        *shell,
                                                 GsPluginLoader *plugin_loader,
                                                 GCancellable   *cancellable);
+void            gs_shell_invalidate            (GsShell        *shell);
+gboolean        gs_shell_is_cache_valid        (GsShell        *shell);
 
 #endif /* __GS_SHELL_H */


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