[gnome-software] Do case-insensitive searching of suitable keywords
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do case-insensitive searching of suitable keywords
- Date: Wed, 14 Jan 2015 11:43:55 +0000 (UTC)
commit a4cdb5f3b88973b7f519c7940b2f07b894ae9765
Author: Richard Hughes <richard hughsie com>
Date: Wed Jan 14 11:42:37 2015 +0000
Do case-insensitive searching of suitable keywords
As gnome-software only checked the length of the search *string*, searches like
'a b c' would pass the 3-char rule and would be executed by the plugin loader.
This caused a very high CPU utilisation, and to the user it looked like the UI
had crashed. Now, only search for keywords once they have been split,
case-folded and checked for appropriate size.
src/gs-plugin-loader.c | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index ac62ae7..9613ba0 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1561,6 +1561,30 @@ gs_plugin_loader_convert_unavailable (GList *list, const gchar *search)
}
/**
+ * gs_plugin_loader_search_tokenize_keywords:
+ **/
+static gchar **
+gs_plugin_loader_search_tokenize_keywords (const gchar *value)
+{
+ gchar **values = NULL;
+ guint i;
+ guint idx = 0;
+ _cleanup_strv_free_ gchar **tmp = NULL;
+
+ /* only add keywords that are long enough */
+ tmp = g_strsplit (value, " ", -1);
+ values = g_new0 (gchar *, g_strv_length (tmp) + 1);
+ for (i = 0; tmp[i] != NULL; i++) {
+ if (strlen (tmp[i]) < 3)
+ continue;
+ values[idx++] = g_utf8_casefold (tmp[i], -1);
+ }
+ if (idx == 0)
+ return NULL;
+ return values;
+}
+
+/**
* gs_plugin_loader_search_thread_cb:
**/
static void
@@ -1581,7 +1605,14 @@ gs_plugin_loader_search_thread_cb (GTask *task,
_cleanup_strv_free_ gchar **values = NULL;
/* run each plugin */
- values = g_strsplit (state->value, " ", -1);
+ values = gs_plugin_loader_search_tokenize_keywords (state->value);
+ if (values == NULL) {
+ g_task_return_new_error (task,
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no valid search terms");
+ goto out;
+ }
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
if (!plugin->enabled)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]