[gnome-software] plugins: Add a GKeyFile cache to datadir-apps to speed up each refine by 308ms per run
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] plugins: Add a GKeyFile cache to datadir-apps to speed up each refine by 308ms per run
- Date: Thu, 7 Mar 2013 16:07:29 +0000 (UTC)
commit d95d7da8c0baf49590b0994c7dd0e56d40d1b56d
Author: Richard Hughes <richard hughsie com>
Date: Thu Mar 7 11:30:44 2013 +0000
plugins: Add a GKeyFile cache to datadir-apps to speed up each refine by 308ms per run
src/plugins/gs-plugin-datadir-apps.c | 60 ++++++++++++++++++++++++++++-----
1 files changed, 51 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/gs-plugin-datadir-apps.c b/src/plugins/gs-plugin-datadir-apps.c
index 8d1fdc0..2af6c85 100644
--- a/src/plugins/gs-plugin-datadir-apps.c
+++ b/src/plugins/gs-plugin-datadir-apps.c
@@ -23,6 +23,10 @@
#include <gs-plugin.h>
+struct GsPluginPrivate {
+ GHashTable *cache;
+};
+
/**
* gs_plugin_get_name:
*/
@@ -33,6 +37,20 @@ gs_plugin_get_name (void)
}
/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* create private area */
+ plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ plugin->priv->cache = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) g_key_file_unref);
+}
+
+/**
* gs_plugin_get_priority:
*/
gdouble
@@ -42,6 +60,15 @@ gs_plugin_get_priority (GsPlugin *plugin)
}
/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+ g_hash_table_unref (plugin->priv->cache);
+}
+
+/**
* gs_plugin_datadir_apps_extract_desktop_data:
*/
static gboolean
@@ -51,7 +78,8 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
GError **error)
{
const gchar *basename_tmp = NULL;
- gboolean ret;
+ gboolean ret = TRUE;
+ gboolean in_cache = FALSE;
gchar *basename = NULL;
gchar *comment = NULL;
gchar *name = NULL;
@@ -59,14 +87,21 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
GKeyFile *key_file;
GdkPixbuf *pixbuf = NULL;
- /* load desktop file */
- key_file = g_key_file_new ();
- ret = g_key_file_load_from_file (key_file,
- desktop_file,
- G_KEY_FILE_NONE,
- error);
- if (!ret)
- goto out;
+ /* is in cache */
+ key_file = g_hash_table_lookup (plugin->priv->cache, desktop_file);
+ if (key_file != NULL) {
+ g_key_file_ref (key_file);
+ in_cache = TRUE;
+ } else {
+ /* load desktop file */
+ key_file = g_key_file_new ();
+ ret = g_key_file_load_from_file (key_file,
+ desktop_file,
+ G_KEY_FILE_NONE,
+ error);
+ if (!ret)
+ goto out;
+ }
/* get desktop name */
name = g_key_file_get_string (key_file,
@@ -121,6 +156,13 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
/* mark as an application */
gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+
+ /* add to cache */
+ if (!in_cache) {
+ g_hash_table_insert (plugin->priv->cache,
+ g_strdup (desktop_file),
+ g_key_file_ref (key_file));
+ }
out:
g_key_file_unref (key_file);
if (pixbuf != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]