[grilo-plugins/wip/carlosg/tracker3: 19/39] tracker3: Port get_media_from_uri() to the statement cache



commit e68adf7c4f9a3b059de3c09111b593deced08b00
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 22 16:26:05 2020 +0200

    tracker3: Port get_media_from_uri() to the statement cache

 src/tracker3/grl-tracker-source-api.c        | 38 ++++++++++------------------
 src/tracker3/grl-tracker-source-statements.c |  2 ++
 src/tracker3/grl-tracker-source-statements.h |  1 +
 3 files changed, 17 insertions(+), 24 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index 6001e990..44bbb970 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -35,6 +35,7 @@
 #include "grl-tracker-source-api.h"
 #include "grl-tracker-source-cache.h"
 #include "grl-tracker-source-priv.h"
+#include "grl-tracker-source-statements.h"
 #include "grl-tracker-utils.h"
 
 /* --------- Logging  -------- */
@@ -137,14 +138,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "a nfo:Media . "                                      \
   "}"
 
-#define TRACKER_MEDIA_FROM_URI_REQUEST          \
-  "SELECT rdf:type(?urn) %s "                   \
-  "WHERE "                                      \
-  "{ "                                          \
-  "?urn nie:url \"%s\" ; "                      \
-  "tracker:available ?tr . "                    \
-  "} "                                          \
-
 /**/
 
 /**/
@@ -529,7 +522,6 @@ tracker_media_from_uri_cb (GObject      *source_object,
 {
   TrackerSparqlStatement    *statement = TRACKER_SPARQL_STATEMENT (source_object); \
   GrlSourceMediaFromUriSpec *mfus = (GrlSourceMediaFromUriSpec *) os->data;
-  GrlTrackerSourcePriv      *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (mfus->source);
   GError                    *tracker_error = NULL, *error = NULL;
   GrlMedia                  *media;
   TrackerSparqlCursor       *cursor;
@@ -1308,9 +1300,7 @@ void
 grl_tracker_source_get_media_from_uri (GrlSource *source,
                                        GrlSourceMediaFromUriSpec *mfus)
 {
-  GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
-  gchar                *sparql_select;
-  gchar                *sparql_final;
+  GError               *error = NULL;
   GrlTrackerOp         *os;
   TrackerSparqlStatement *statement;
 
@@ -1320,25 +1310,25 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
   if (!g_list_find (mfus->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_ID)))
     mfus->keys = g_list_prepend (mfus->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_ID));
 
-  sparql_select = grl_tracker_source_get_select_string (mfus->keys);
-  sparql_final = g_strdup_printf (TRACKER_MEDIA_FROM_URI_REQUEST,
-                                  sparql_select,
-                                  mfus->uri);
-
-  GRL_IDEBUG ("\tselect: '%s'", sparql_final);
-
-  statement =
-    tracker_sparql_connection_query_statement (priv->tracker_connection,
-                                               sparql_final,
-                                               NULL, NULL);
+  statement = grl_tracker_source_create_statement (GRL_TRACKER_SOURCE (source),
+                                                   GRL_TRACKER_QUERY_MEDIA_FROM_URI,
+                                                   mfus->options,
+                                                   mfus->keys,
+                                                   NULL,
+                                                   &error);
+  if (!statement) {
+    mfus->callback (source, mfus->operation_id, NULL, NULL, error);
+    g_error_free (error);
+    return;
+  }
 
   os = grl_tracker_op_new (GRL_TYPE_FILTER_ALL, mfus->keys, mfus);
 
+  tracker_sparql_statement_bind_string (statement, "uri", mfus->uri);
   tracker_sparql_statement_execute_async (statement,
                                           os->cancel,
                                           (GAsyncReadyCallback) tracker_media_from_uri_cb,
                                           os);
 
-  g_free (sparql_select);
   g_clear_object (&statement);
 }
diff --git a/src/tracker3/grl-tracker-source-statements.c b/src/tracker3/grl-tracker-source-statements.c
index 404b4449..d342a9cb 100644
--- a/src/tracker3/grl-tracker-source-statements.c
+++ b/src/tracker3/grl-tracker-source-statements.c
@@ -53,6 +53,8 @@ struct _CachedStatement
 };
 
 static const gchar *query_bases[GRL_TRACKER_QUERY_N_QUERIES] = {
+  /* GRL_TRACKER_QUERY_MEDIA_FROM_URI */
+  "?urn nie:url ~uri ",
 };
 
 static void
diff --git a/src/tracker3/grl-tracker-source-statements.h b/src/tracker3/grl-tracker-source-statements.h
index 3c4bbb95..416be573 100644
--- a/src/tracker3/grl-tracker-source-statements.h
+++ b/src/tracker3/grl-tracker-source-statements.h
@@ -34,6 +34,7 @@
 /**/
 
 typedef enum {
+  GRL_TRACKER_QUERY_MEDIA_FROM_URI, /* Arguments: ~uri */
   GRL_TRACKER_QUERY_N_QUERIES,
 } GrlTrackerQueryType;
 


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