summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-11-02 15:05:26 +0000
committerRichard Hughes <richard@hughsie.com>2016-11-02 15:05:26 +0000
commit8bfba559004253aeabcf9a26f4edd7cccbe70770 (patch)
treefcd7a5534b0245c88010da9b8d19e80c480b1447
parent927d4d3856b914511f5a52114c583c5d35c643f4 (diff)
downloadappstream-glib-8bfba559004253aeabcf9a26f4edd7cccbe70770.tar.gz
Add as_store_load_search_cache()
This is really only useful for profiling startup speed.
-rw-r--r--client/as-util.c3
-rw-r--r--libappstream-glib/as-store.c32
-rw-r--r--libappstream-glib/as-store.h1
3 files changed, 36 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c
index 4be1f1d..dee4934 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -1301,6 +1301,9 @@ as_util_search (AsUtilPrivate *priv, gchar **values, GError **error)
NULL, error))
return FALSE;
+ /* prime the search cache */
+ as_store_load_search_cache (store);
+
/* add matches to an array */
apps = as_store_get_apps (store);
array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index c63aaf7..62b219f 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -2925,6 +2925,38 @@ as_store_search_per_user (AsStore *store,
}
/**
+ * as_store_load_search_cache:
+ * @store: a #AsStore instance.
+ *
+ * Populates the token cache for all applications in the store. This allows
+ * all the search keywords for all applications in the store to be
+ * pre-processed at one time rather than on demand.
+ *
+ * Note: Calling as_app_search_matches() automatically generates the search
+ * cache for the #AsApp object if it has not already been generated.
+ *
+ * Since: 0.6.5
+ **/
+void
+as_store_load_search_cache (AsStore *store)
+{
+ AsStorePrivate *priv = GET_PRIVATE (store);
+ guint i;
+ g_autoptr(AsProfileTask) ptask = NULL;
+
+ /* profile */
+ ptask = as_profile_start_literal (priv->profile,
+ "AsStore:load-token-cache");
+ g_assert (ptask != NULL);
+
+ /* load the token cache for each app */
+ for (i = 0; i < priv->array->len; i++) {
+ AsApp *app = g_ptr_array_index (priv->array, i);
+ as_app_search_matches (app, NULL);
+ }
+}
+
+/**
* as_store_load:
* @store: a #AsStore instance.
* @flags: #AsStoreLoadFlags, e.g. %AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM
diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h
index fd41a00..3d4a34a 100644
--- a/libappstream-glib/as-store.h
+++ b/libappstream-glib/as-store.h
@@ -182,6 +182,7 @@ gboolean as_store_load_path (AsStore *store,
const gchar *path,
GCancellable *cancellable,
GError **error);
+void as_store_load_search_cache (AsStore *store);
void as_store_remove_all (AsStore *store);
GPtrArray *as_store_get_apps (AsStore *store);
GPtrArray *as_store_get_apps_by_id (AsStore *store,