summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-11-20 19:04:39 +0100
committerCarlos Garnacho <carlosg@gnome.org>2015-11-23 17:58:34 +0100
commitf6dd0438d12a2cc6a298b08fc3992bef5cb8d542 (patch)
tree2f324a0f149cab95c73dfbdd150258e71967aa24
parent61d6c1a523385cc1fe724cbe1cc8ad9545e6cc43 (diff)
downloadgtk+-f6dd0438d12a2cc6a298b08fc3992bef5cb8d542.tar.gz
searchenginetracker: Optimize direct/recursive folder lookups
tracker:uri-is-descendant/parent has the unfortunate side effect of rendering the collation mechanisms in the database useless, so those require full table scans to be validated. Performing these as pure string comparisons will perform much better, as those allow the underlying sqlite to rely on its own collation to perform the search, which can be significantly faster with many elements in the database. https://bugzilla.gnome.org/show_bug.cgi?id=758407
-rw-r--r--gtk/gtksearchenginetracker.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c
index 31da5089ce..02e74085aa 100644
--- a/gtk/gtksearchenginetracker.c
+++ b/gtk/gtksearchenginetracker.c
@@ -227,7 +227,8 @@ sparql_escape_string (const gchar *literal)
static void
sparql_append_string_literal (GString *sparql,
const gchar *str,
- gboolean glob)
+ gboolean glob,
+ gboolean is_dir_uri)
{
gchar *s;
@@ -236,6 +237,8 @@ sparql_append_string_literal (GString *sparql,
g_string_append_c (sparql, '"');
g_string_append (sparql, s);
+ if (is_dir_uri)
+ g_string_append_c (sparql, '/');
if (glob)
g_string_append_c (sparql, '*');
g_string_append_c (sparql, '"');
@@ -250,7 +253,7 @@ sparql_append_string_literal_lower_case (GString *sparql,
gchar *s;
s = g_utf8_strdown (str, -1);
- sparql_append_string_literal (sparql, s, FALSE);
+ sparql_append_string_literal (sparql, s, FALSE, FALSE);
g_free (s);
}
@@ -347,11 +350,12 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
"WHERE {"
" ?urn a nfo:FileDataObject ;"
" tracker:available true ; ");
+ " nfo:belongsToContainer ?parent; ");
#ifdef FTS_MATCHING
/* Using FTS: */
g_string_append (sparql, "fts:match ");
- sparql_append_string_literal (sparql, search_text, TRUE);
+ sparql_append_string_literal (sparql, search_text, TRUE, FALSE);
#endif
g_string_append (sparql, ". FILTER (BOUND(nie:url(?urn)) && ");
@@ -365,11 +369,16 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
gchar *location_uri = g_file_get_uri (location);
g_string_append (sparql, " && ");
if (recursive)
- g_string_append (sparql, "tracker:uri-is-descendant(");
+ {
+ g_string_append (sparql, "fn:starts-with(nie:url(?urn),");
+ sparql_append_string_literal (sparql, location_uri, FALSE, TRUE);
+ g_string_append (sparql, ")");
+ }
else
- g_string_append (sparql, "tracker:uri-is-parent(");
- sparql_append_string_literal (sparql, location_uri, FALSE);
- g_string_append (sparql, ",nie:url(?urn))");
+ {
+ g_string_append (sparql, "nie:url(?parent) = ");
+ sparql_append_string_literal (sparql, location_uri, FALSE, FALSE);
+ }
g_free (location_uri);
}