[tracker] tracker-extract: Use safer method to insert tags in PNG module
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-extract: Use safer method to insert tags in PNG module
- Date: Mon, 14 Mar 2016 22:28:45 +0000 (UTC)
commit 493084b06137824c8cd1d6673a77d6a51cca5df0
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Mar 14 12:46:05 2016 +0100
tracker-extract: Use safer method to insert tags in PNG module
The current way of inserting the nao:hasTag relationship on the
extracted file involves one join operation per tag being inserted.
This has performance implications, plus we can feasibly hit the
sqlite limit of 64 tables in joins.
Instead insert the tags in separate inserts, that will be as fast
as it gets, plus there's no limit in the number of tags.
src/tracker-extract/tracker-extract-png.c | 64 +++++++++++++----------------
1 files changed, 29 insertions(+), 35 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 45d4836..a7aa705 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -185,12 +185,12 @@ raw_profile_new (const gchar *input,
static void
read_metadata (TrackerSparqlBuilder *preupdate,
TrackerSparqlBuilder *metadata,
- GString *where,
png_structp png_ptr,
png_infop info_ptr,
png_infop end_ptr,
const gchar *uri,
- const gchar *graph)
+ const gchar *graph,
+ const gchar *urn)
{
MergeData md = { 0 };
PngData pd = { 0 };
@@ -361,7 +361,7 @@ read_metadata (TrackerSparqlBuilder *preupdate,
md.make = tracker_coalesce_strip (2, xd->make, ed->make);
md.model = tracker_coalesce_strip (2, xd->model, ed->model);
- keywords = g_ptr_array_new ();
+ keywords = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
if (md.comment) {
tracker_sparql_builder_predicate (metadata, "nie:comment");
@@ -695,31 +695,21 @@ read_metadata (TrackerSparqlBuilder *preupdate,
}
for (i = 0; i < keywords->len; i++) {
- gchar *p, *escaped, *var;
+ gchar *escaped, *subject;
+ const gchar *p;
p = g_ptr_array_index (keywords, i);
escaped = tracker_sparql_escape_string (p);
- var = g_strdup_printf ("tag%d", i + 1);
+ subject = g_strdup_printf ("_:tag%d", i + 1);
/* ensure tag with specified label exists */
- tracker_sparql_builder_append (preupdate, "INSERT { ");
-
- if (graph) {
- tracker_sparql_builder_append (preupdate, "GRAPH <");
- tracker_sparql_builder_append (preupdate, graph);
- tracker_sparql_builder_append (preupdate, "> { ");
- }
-
- tracker_sparql_builder_append (preupdate,
- "_:tag a nao:Tag ; nao:prefLabel \"");
- tracker_sparql_builder_append (preupdate, escaped);
- tracker_sparql_builder_append (preupdate, "\"");
-
- if (graph) {
- tracker_sparql_builder_append (preupdate, " } ");
- }
-
- tracker_sparql_builder_append (preupdate, " }\n");
+ tracker_sparql_builder_insert_open (preupdate, graph);
+ tracker_sparql_builder_subject (preupdate, subject);
+ tracker_sparql_builder_predicate (preupdate, "a");
+ tracker_sparql_builder_object (preupdate, "nao:Tag");
+ tracker_sparql_builder_predicate (preupdate, "nao:prefLabel");
+ tracker_sparql_builder_object_unvalidated (preupdate, escaped);
+ tracker_sparql_builder_insert_close (preupdate);
tracker_sparql_builder_append (preupdate,
"WHERE { FILTER (NOT EXISTS { "
"?tag a nao:Tag ; nao:prefLabel \"");
@@ -728,14 +718,21 @@ read_metadata (TrackerSparqlBuilder *preupdate,
"\" }) }\n");
/* associate file with tag */
- tracker_sparql_builder_predicate (metadata, "nao:hasTag");
- tracker_sparql_builder_object_variable (metadata, var);
-
- g_string_append_printf (where, "?%s a nao:Tag ; nao:prefLabel \"%s\" .\n", var, escaped);
+ tracker_sparql_builder_insert_open (preupdate, graph);
+ tracker_sparql_builder_subject_iri (preupdate, urn);
+ tracker_sparql_builder_predicate (preupdate, "nao:hasTag");
+ tracker_sparql_builder_object (preupdate, "?tag");
+ tracker_sparql_builder_insert_close (preupdate);
+ tracker_sparql_builder_where_open (preupdate);
+ tracker_sparql_builder_subject (preupdate, "?tag");
+ tracker_sparql_builder_predicate (preupdate, "a");
+ tracker_sparql_builder_object (preupdate, "nao:Tag");
+ tracker_sparql_builder_predicate (preupdate, "nao:prefLabel");
+ tracker_sparql_builder_object_unvalidated (preupdate, escaped);
+ tracker_sparql_builder_where_close (preupdate);
- g_free (var);
+ g_free (subject);
g_free (escaped);
- g_free (p);
}
g_ptr_array_free (keywords, TRUE);
@@ -796,10 +793,9 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
png_uint_32 width, height;
gint bit_depth, color_type;
gint interlace_type, compression_type, filter_type;
- const gchar *dlna_profile, *dlna_mimetype, *graph;
+ const gchar *dlna_profile, *dlna_mimetype, *graph, *urn;
TrackerSparqlBuilder *preupdate, *metadata;
gchar *filename, *uri;
- GString *where;
GFile *file;
file = tracker_extract_info_get_file (info);
@@ -809,6 +805,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
preupdate = tracker_extract_info_get_preupdate_builder (info);
metadata = tracker_extract_info_get_metadata_builder (info);
graph = tracker_extract_info_get_graph (info);
+ urn = tracker_extract_info_get_urn (info);
if (size < 64) {
return FALSE;
@@ -892,11 +889,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_sparql_builder_object (metadata, "nmm:Photo");
uri = g_file_get_uri (file);
- where = g_string_new ("");
- read_metadata (preupdate, metadata, where, png_ptr, info_ptr, end_ptr, uri, graph);
- tracker_extract_info_set_where_clause (info, where->str);
- g_string_free (where, TRUE);
+ read_metadata (preupdate, metadata, png_ptr, info_ptr, end_ptr, uri, graph, urn);
g_free (uri);
tracker_sparql_builder_predicate (metadata, "nfo:width");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]