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
This commit is contained in:
Carlos Garnacho 2015-11-20 19:04:39 +01:00
parent 61d6c1a523
commit f6dd0438d1

View File

@ -227,7 +227,8 @@ sparql_escape_string (const gchar *literal)
static void static void
sparql_append_string_literal (GString *sparql, sparql_append_string_literal (GString *sparql,
const gchar *str, const gchar *str,
gboolean glob) gboolean glob,
gboolean is_dir_uri)
{ {
gchar *s; gchar *s;
@ -236,6 +237,8 @@ sparql_append_string_literal (GString *sparql,
g_string_append_c (sparql, '"'); g_string_append_c (sparql, '"');
g_string_append (sparql, s); g_string_append (sparql, s);
if (is_dir_uri)
g_string_append_c (sparql, '/');
if (glob) if (glob)
g_string_append_c (sparql, '*'); g_string_append_c (sparql, '*');
g_string_append_c (sparql, '"'); g_string_append_c (sparql, '"');
@ -250,7 +253,7 @@ sparql_append_string_literal_lower_case (GString *sparql,
gchar *s; gchar *s;
s = g_utf8_strdown (str, -1); s = g_utf8_strdown (str, -1);
sparql_append_string_literal (sparql, s, FALSE); sparql_append_string_literal (sparql, s, FALSE, FALSE);
g_free (s); g_free (s);
} }
@ -347,11 +350,12 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
"WHERE {" "WHERE {"
" ?urn a nfo:FileDataObject ;" " ?urn a nfo:FileDataObject ;"
" tracker:available true ; "); " tracker:available true ; ");
" nfo:belongsToContainer ?parent; ");
#ifdef FTS_MATCHING #ifdef FTS_MATCHING
/* Using FTS: */ /* Using FTS: */
g_string_append (sparql, "fts:match "); g_string_append (sparql, "fts:match ");
sparql_append_string_literal (sparql, search_text, TRUE); sparql_append_string_literal (sparql, search_text, TRUE, FALSE);
#endif #endif
g_string_append (sparql, ". FILTER (BOUND(nie:url(?urn)) && "); 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); gchar *location_uri = g_file_get_uri (location);
g_string_append (sparql, " && "); g_string_append (sparql, " && ");
if (recursive) 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 else
g_string_append (sparql, "tracker:uri-is-parent("); {
sparql_append_string_literal (sparql, location_uri, FALSE); g_string_append (sparql, "nie:url(?parent) = ");
g_string_append (sparql, ",nie:url(?urn))"); sparql_append_string_literal (sparql, location_uri, FALSE, FALSE);
}
g_free (location_uri); g_free (location_uri);
} }