[grilo-plugins/wip/carlosg/tracker3: 6/37] tracker3: Use TrackerSparqlStatement for queries
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins/wip/carlosg/tracker3: 6/37] tracker3: Use TrackerSparqlStatement for queries
- Date: Mon, 25 May 2020 13:19:12 +0000 (UTC)
commit 5b7f730058131791d6bc88a8f7177ad88db2b8fa
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue May 19 17:48:32 2020 +0200
tracker3: Use TrackerSparqlStatement for queries
The port is shoddy atm, queries will be updated to making use of this
one by one.
src/tracker3/grl-tracker-request-queue.c | 46 ++++++++++++++++-----
src/tracker3/grl-tracker-request-queue.h | 18 ++++----
src/tracker3/grl-tracker-source-api.c | 70 +++++++++++++++++++++++---------
src/tracker3/grl-tracker-utils.c | 4 +-
4 files changed, 99 insertions(+), 39 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-request-queue.c b/src/tracker3/grl-tracker-request-queue.c
index fb7d59ea..ac9f42ea 100644
--- a/src/tracker3/grl-tracker-request-queue.c
+++ b/src/tracker3/grl-tracker-request-queue.c
@@ -42,6 +42,8 @@ grl_tracker_op_terminate (GrlTrackerOp *os)
if (os == NULL)
return;
+ g_clear_object (&os->statement);
+ g_clear_pointer (&os->arguments, g_hash_table_unref);
g_clear_object (&os->cursor);
g_object_unref (os->cancel);
g_free (os->request);
@@ -65,17 +67,20 @@ grl_tracker_op_initiate (gchar *request,
}
GrlTrackerOp *
-grl_tracker_op_initiate_query (guint operation_id,
- gchar *request,
- GAsyncReadyCallback callback,
- gpointer data)
+grl_tracker_op_initiate_query (guint operation_id,
+ TrackerSparqlStatement *statement,
+ GHashTable *arguments,
+ GAsyncReadyCallback callback,
+ gpointer data)
{
- GrlTrackerOp *os = grl_tracker_op_initiate (request,
+ GrlTrackerOp *os = grl_tracker_op_initiate (NULL,
callback,
data);
os->type = GRL_TRACKER_OP_TYPE_QUERY;
os->operation_id = operation_id;
+ os->statement = g_object_ref (statement);
+ os->arguments = arguments ? g_hash_table_ref (arguments) : NULL;
/* g_hash_table_insert (grl_tracker_operations, */
/* GSIZE_TO_POINTER (operation_id), os); */
@@ -84,15 +89,18 @@ grl_tracker_op_initiate_query (guint operation_id,
}
GrlTrackerOp *
-grl_tracker_op_initiate_metadata (gchar *request,
- GAsyncReadyCallback callback,
- gpointer data)
+grl_tracker_op_initiate_metadata (TrackerSparqlStatement *statement,
+ GHashTable *arguments,
+ GAsyncReadyCallback callback,
+ gpointer data)
{
- GrlTrackerOp *os = grl_tracker_op_initiate (request,
+ GrlTrackerOp *os = grl_tracker_op_initiate (NULL,
callback,
data);
os->type = GRL_TRACKER_OP_TYPE_QUERY;
+ os->statement = g_object_ref (statement);
+ os->arguments = arguments ? g_hash_table_ref (arguments) : NULL;
return os;
}
@@ -111,13 +119,29 @@ grl_tracker_op_initiate_set_metadata (gchar *request,
return os;
}
+static void
+set_up_statement (TrackerSparqlStatement *statement,
+ GHashTable *arguments)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ if (!arguments)
+ return;
+
+ g_hash_table_iter_init (&iter, arguments);
+
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ tracker_sparql_statement_bind_string (statement, key, value);
+}
+
static void
grl_tracker_op_start (GrlTrackerOp *os)
{
switch (os->type) {
case GRL_TRACKER_OP_TYPE_QUERY:
- tracker_sparql_connection_query_async (grl_tracker_connection,
- os->request,
+ set_up_statement (os->statement, os->arguments);
+ tracker_sparql_statement_execute_async (os->statement,
NULL,
os->callback,
os);
diff --git a/src/tracker3/grl-tracker-request-queue.h b/src/tracker3/grl-tracker-request-queue.h
index 8805b9cf..a5c81e10 100644
--- a/src/tracker3/grl-tracker-request-queue.h
+++ b/src/tracker3/grl-tracker-request-queue.h
@@ -40,6 +40,8 @@ typedef struct {
GAsyncReadyCallback callback;
GCancellable *cancel;
TrackerSparqlConnection *connection;
+ TrackerSparqlStatement *statement;
+ GHashTable *arguments;
gchar *request;
const GList *keys;
gpointer data;
@@ -58,14 +60,16 @@ typedef struct _GrlTrackerQueue GrlTrackerQueue;
/**/
-GrlTrackerOp *grl_tracker_op_initiate_query (guint operation_id,
- gchar *request,
- GAsyncReadyCallback callback,
- gpointer data);
+GrlTrackerOp *grl_tracker_op_initiate_query (guint operation_id,
+ TrackerSparqlStatement *statement,
+ GHashTable *arguments,
+ GAsyncReadyCallback callback,
+ gpointer data);
-GrlTrackerOp *grl_tracker_op_initiate_metadata (gchar *request,
- GAsyncReadyCallback callback,
- gpointer data);
+GrlTrackerOp *grl_tracker_op_initiate_metadata (TrackerSparqlStatement *statement,
+ GHashTable *arguments,
+ GAsyncReadyCallback callback,
+ gpointer data);
GrlTrackerOp *grl_tracker_op_initiate_set_metadata (gchar *request,
GAsyncReadyCallback callback,
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index eed651f7..e627c237 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -81,8 +81,7 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
"%s %s " \
"} " \
"ORDER BY DESC(nfo:fileLastModified(?urn)) " \
- "OFFSET %u " \
- "LIMIT %u"
+ TRACKER_QUERY_LIMIT
#define TRACKER_SEARCH_ALL_REQUEST \
"SELECT DISTINCT rdf:type(?urn) %s " \
@@ -93,8 +92,7 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
"%s %s " \
"} " \
"ORDER BY DESC(nfo:fileLastModified(?urn)) " \
- "OFFSET %u " \
- "LIMIT %u"
+ TRACKER_QUERY_LIMIT
#define TRACKER_BROWSE_CATEGORY_REQUEST \
"SELECT rdf:type(?urn) %s " \
@@ -107,8 +105,7 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
"%s " \
"} " \
"ORDER BY DESC(nfo:fileLastModified(?urn)) " \
- "OFFSET %u " \
- "LIMIT %u"
+ TRACKER_QUERY_LIMIT
#define TRACKER_RESOLVE_REQUEST \
"SELECT %s " \
@@ -427,14 +424,12 @@ get_sparql_type_filter (GrlOperationOptions *options,
{ \
GError *tracker_error = NULL, *error = NULL; \
spec_type *spec = (spec_type *) os->data; \
- TrackerSparqlConnection *connection = \
- grl_tracker_source_get_tracker_connection (GRL_TRACKER_SOURCE (spec->source)); \
\
GRL_ODEBUG ("%s", __FUNCTION__); \
\
os->cursor = \
- tracker_sparql_connection_query_finish (connection, \
- result, &tracker_error); \
+ tracker_sparql_statement_execute_finish (os->statement, \
+ result, &tracker_error); \
\
if (tracker_error) { \
GRL_WARNING ("Could not execute sparql query id=%u: %s", \
@@ -479,8 +474,8 @@ tracker_resolve_cb (GObject *source_object,
GRL_ODEBUG ("%s", __FUNCTION__);
- cursor = tracker_sparql_connection_query_finish (priv->tracker_connection,
- result, &tracker_error);
+ cursor = tracker_sparql_statement_execute_finish (os->statement,
+ result, &tracker_error);
if (tracker_error) {
GRL_WARNING ("Could not execute sparql resolve query : %s",
@@ -534,8 +529,8 @@ tracker_media_from_uri_cb (GObject *source_object,
GRL_ODEBUG ("%s", __FUNCTION__);
- cursor = tracker_sparql_connection_query_finish (priv->tracker_connection,
- result, &tracker_error);
+ cursor = tracker_sparql_statement_execute_finish (os->statement,
+ result, &tracker_error);
if (tracker_error) {
GRL_WARNING ("Could not execute sparql media from uri query : %s",
@@ -768,6 +763,7 @@ grl_tracker_source_query (GrlSource *source,
GrlTrackerOp *os;
gint count = grl_operation_options_get_count (qs->options);
guint skip = grl_operation_options_get_skip (qs->options);
+ TrackerSparqlStatement *statement;
GRL_IDEBUG ("%s: id=%u", __FUNCTION__, qs->operation_id);
@@ -802,8 +798,13 @@ grl_tracker_source_query (GrlSource *source,
qs->query = sparql_final;
}
+ statement =
+ tracker_sparql_connection_query_statement (priv->tracker_connection,
+ qs->query,
+ NULL, NULL);
+
os = grl_tracker_op_initiate_query (qs->operation_id,
- g_strdup (qs->query),
+ statement, NULL,
(GAsyncReadyCallback) tracker_query_cb,
qs);
@@ -817,6 +818,8 @@ grl_tracker_source_query (GrlSource *source,
grl_tracker_queue_push (grl_tracker_queue, os);
+ g_clear_object (&statement);
+
return;
send_error:
@@ -833,6 +836,7 @@ grl_tracker_source_resolve (GrlSource *source,
gchar *sparql_type_filter = NULL;
const gchar *url = grl_media_get_url (rs->media);
GrlTrackerOp *os;
+ TrackerSparqlStatement *statement;
GRL_IDEBUG ("%s: id=%i", __FUNCTION__, rs->operation_id);
@@ -859,7 +863,12 @@ grl_tracker_source_resolve (GrlSource *source,
GRL_IDEBUG ("\request: '%s'", sparql_final);
- os = grl_tracker_op_initiate_metadata (sparql_final,
+ statement =
+ tracker_sparql_connection_query_statement (priv->tracker_connection,
+ sparql_final,
+ NULL, NULL);
+
+ os = grl_tracker_op_initiate_metadata (statement, NULL,
(GAsyncReadyCallback) tracker_resolve_cb,
rs);
os->keys = rs->keys;
@@ -869,6 +878,7 @@ grl_tracker_source_resolve (GrlSource *source,
g_clear_pointer (&sparql_type_filter, g_free);
g_clear_pointer (&constraint, g_free);
g_clear_pointer (&sparql_select, g_free);
+ g_clear_object (&statement);
}
gboolean
@@ -955,6 +965,8 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
guint skip = grl_operation_options_get_skip (ss->options);
int min_dur, max_dur;
char *duration_constraint;
+ TrackerSparqlStatement *statement;
+
GRL_IDEBUG ("%s: id=%u", __FUNCTION__, ss->operation_id);
constraint = grl_tracker_source_get_device_constraint (priv);
@@ -977,8 +989,13 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
GRL_IDEBUG ("\tselect: '%s'", sparql_final);
+ statement =
+ tracker_sparql_connection_query_statement (priv->tracker_connection,
+ sparql_final,
+ NULL, NULL);
+
os = grl_tracker_op_initiate_query (ss->operation_id,
- sparql_final,
+ statement, NULL,
(GAsyncReadyCallback) tracker_search_cb,
ss);
os->keys = ss->keys;
@@ -992,6 +1009,7 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
g_free (sparql_select);
g_free (sparql_type_filter);
g_free (duration_constraint);
+ g_clear_object (&statement);
}
static gboolean
@@ -1021,6 +1039,7 @@ grl_tracker_source_browse_category (GrlSource *source,
GrlTypeFilter filter = grl_operation_options_get_type_filter (bs->options);
int min_dur, max_dur;
char *duration_constraint;
+ TrackerSparqlStatement *statement;
GRL_IDEBUG ("%s: id=%u", __FUNCTION__, bs->operation_id);
@@ -1146,8 +1165,13 @@ grl_tracker_source_browse_category (GrlSource *source,
GRL_IDEBUG ("\tselect: '%s'", sparql_final);
+ statement =
+ tracker_sparql_connection_query_statement (priv->tracker_connection,
+ sparql_final,
+ NULL, NULL);
+
os = grl_tracker_op_initiate_query (bs->operation_id,
- sparql_final,
+ statement, NULL,
(GAsyncReadyCallback) tracker_browse_cb,
bs);
os->keys = bs->keys;
@@ -1160,6 +1184,7 @@ grl_tracker_source_browse_category (GrlSource *source,
g_free (constraint);
g_free (sparql_select);
g_free (duration_constraint);
+ g_clear_object (&statement);
}
void
@@ -1315,6 +1340,7 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
gchar *sparql_select;
gchar *sparql_final;
GrlTrackerOp *os;
+ TrackerSparqlStatement *statement;
GRL_IDEBUG ("%s: id=%u", __FUNCTION__, mfus->operation_id);
@@ -1331,7 +1357,12 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
GRL_IDEBUG ("\tselect: '%s'", sparql_final);
- os = grl_tracker_op_initiate_metadata (sparql_final,
+ statement =
+ tracker_sparql_connection_query_statement (priv->tracker_connection,
+ sparql_final,
+ NULL, NULL);
+
+ os = grl_tracker_op_initiate_metadata (statement, NULL,
(GAsyncReadyCallback) tracker_media_from_uri_cb,
mfus);
os->keys = mfus->keys;
@@ -1340,4 +1371,5 @@ grl_tracker_source_get_media_from_uri (GrlSource *source,
g_free (constraint);
g_free (sparql_select);
+ g_clear_object (&statement);
}
diff --git a/src/tracker3/grl-tracker-utils.c b/src/tracker3/grl-tracker-utils.c
index e83ec5e1..79bbb39c 100644
--- a/src/tracker3/grl-tracker-utils.c
+++ b/src/tracker3/grl-tracker-utils.c
@@ -393,8 +393,8 @@ grl_tracker_setup_key_mappings (void)
"video");
insert_key_mapping (GRL_METADATA_KEY_SEASON,
- "nmm:season",
- "nmm:season(?urn)",
+ NULL,
+ "nmm:seasonNumber(nmm:isPartOfSeason(?urn))",
"video");
insert_key_mapping (GRL_METADATA_KEY_EPISODE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]