[tracker] tracker-extract: Use safer method to insert tags in JPEG module



commit 9153e5d4e3ec0c694aaad98962359afb8eb3a06e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 14 12:45:42 2016 +0100

    tracker-extract: Use safer method to insert tags in JPEG 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-jpeg.c |   60 ++++++++++++----------------
 1 files changed, 26 insertions(+), 34 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index 807555b..8097a7b 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -145,15 +145,15 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
        goffset size;
        gchar *filename, *uri;
        gchar *comment = NULL;
-       const gchar *dlna_profile, *dlna_mimetype, *graph;
+       const gchar *dlna_profile, *dlna_mimetype, *graph, *urn;
        GPtrArray *keywords;
        gboolean success = TRUE;
-       GString *where;
        guint i;
 
        metadata = tracker_extract_info_get_metadata_builder (info);
        preupdate = tracker_extract_info_get_preupdate_builder (info);
        graph = tracker_extract_info_get_graph (info);
+       urn = tracker_extract_info_get_urn (info);
 
        file = tracker_extract_info_get_file (info);
        filename = g_file_get_path (file);
@@ -343,7 +343,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                g_free (uri);
        }
 
-       keywords = g_ptr_array_new ();
+       keywords = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
 
        if (xd->keywords) {
                tracker_keywords_parse (keywords, xd->keywords);
@@ -434,34 +434,22 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                tracker_keywords_parse (keywords, id->keywords);
        }
 
-       where = g_string_new ("");
-
        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 \"");
@@ -470,20 +458,24 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                                               "\" }) }\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);
 
-       tracker_extract_info_set_where_clause (info, where->str);
-       g_string_free (where, TRUE);
-
        if (md.make || md.model) {
                gchar *equip_uri;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]