[gnome-software/wip/hughsie/cachekey: 4/4] Allow GsApp objects to implement a custom cache key
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/cachekey: 4/4] Allow GsApp objects to implement a custom cache key
- Date: Thu, 20 Jun 2019 10:58:03 +0000 (UTC)
commit 9ff905cd53a94774c8b13c214b3aa6cd348f0b68
Author: Richard Hughes <richard hughsie com>
Date: Thu Jun 20 11:31:46 2019 +0100
Allow GsApp objects to implement a custom cache key
This allows us to maintain a plugin cache when the unique ID is not unique
enough to disambiguate the objects. For instance, flatpak applications created
from an AppStream search result do not have a "branch" set.
Fixes https://gitlab.gnome.org/GNOME/gnome-software/issues/684
lib/gs-app.c | 21 +++++++++++++++++++++
lib/gs-app.h | 4 +++-
plugins/core/gs-appstream.c | 2 +-
plugins/flatpak/gs-flatpak-app.c | 8 ++++++++
4 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 186ceb54..7fefc7b4 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -1260,6 +1260,27 @@ gs_app_get_unique_id (GsApp *app)
return gs_app_get_unique_id_unlocked (app);
}
+/**
+ * gs_app_get_cache_key:
+ * @app: a #GsApp
+ *
+ * Gets the cache key used for de-duplication.
+ * If the plugin has not provided a custom #GsApp subclass with the `get_cache_key`
+ * vfunc implemented then gs_app_get_unique_id() will be used.
+ *
+ * Returns: A string ID suitable for deduplication
+ *
+ * Since: 3.34
+ **/
+const gchar *
+gs_app_get_cache_key (GsApp *app)
+{
+ GsAppClass *klass = GS_APP_GET_CLASS (app);
+ if (klass->get_cache_key != NULL)
+ return klass->get_cache_key (app);
+ return gs_app_get_unique_id (app);
+}
+
/**
* gs_app_set_unique_id:
* @app: a #GsApp
diff --git a/lib/gs-app.h b/lib/gs-app.h
index cd185154..35240081 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -26,7 +26,8 @@ struct _GsAppClass
GObjectClass parent_class;
void (*to_string) (GsApp *app,
GString *str);
- gpointer padding[30];
+ const gchar *(*get_cache_key) (GsApp *app);
+ gpointer padding[29];
};
/**
@@ -191,6 +192,7 @@ gboolean gs_app_get_allow_cancel (GsApp *app);
void gs_app_set_allow_cancel (GsApp *app,
gboolean allow_cancel);
const gchar *gs_app_get_unique_id (GsApp *app);
+const gchar *gs_app_get_cache_key (GsApp *app);
const gchar *gs_app_get_branch (GsApp *app);
void gs_app_set_branch (GsApp *app,
const gchar *branch);
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index edab1271..f680f656 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -27,7 +27,7 @@ gs_appstream_create_app (GsPlugin *plugin, XbSilo *silo, XbNode *component, GErr
return NULL;
/* look for existing object */
- app = gs_plugin_cache_lookup (plugin, gs_app_get_unique_id (app_new));
+ app = gs_plugin_cache_lookup (plugin, gs_app_get_cache_key (app_new));
if (app != NULL)
return app;
diff --git a/plugins/flatpak/gs-flatpak-app.c b/plugins/flatpak/gs-flatpak-app.c
index 0f587877..50885557 100644
--- a/plugins/flatpak/gs-flatpak-app.c
+++ b/plugins/flatpak/gs-flatpak-app.c
@@ -51,6 +51,13 @@ gs_flatpak_app_file_kind_to_string (GsFlatpakAppFileKind file_kind)
return NULL;
}
+static const gchar *
+gs_flatpak_app_get_cache_key (GsApp *app)
+{
+ /* created by AppStream to be 'runtime/org.test.Runtime/x86_64/master' */
+ return gs_app_get_source_default (app);
+}
+
static void
gs_flatpak_app_to_string (GsApp *app, GString *str)
{
@@ -296,6 +303,7 @@ gs_flatpak_app_class_init (GsFlatpakAppClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GsAppClass *klass_app = GS_APP_CLASS (klass);
klass_app->to_string = gs_flatpak_app_to_string;
+ klass_app->get_cache_key = gs_flatpak_app_get_cache_key;
object_class->finalize = gs_flatpak_app_finalize;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]