[tracker/writeback-guarantee: 7/7] tracker-writeback: Merge the two queries into one
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/writeback-guarantee: 7/7] tracker-writeback: Merge the two queries into one
- Date: Mon, 20 Dec 2010 11:05:47 +0000 (UTC)
commit 4d9ec6e96df38eddddd6ddc4a87b598470645ae8
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Dec 20 12:04:12 2010 +0100
tracker-writeback: Merge the two queries into one
src/tracker-writeback/tracker-writeback-consumer.c | 145 +++-----------------
1 files changed, 22 insertions(+), 123 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-consumer.c b/src/tracker-writeback/tracker-writeback-consumer.c
index e0ea33e..83d9a66 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.c
+++ b/src/tracker-writeback/tracker-writeback-consumer.c
@@ -57,17 +57,6 @@ typedef struct {
guint state;
} TrackerWritebackConsumerPrivate;
-typedef struct {
- TrackerWritebackConsumer *consumer;
- GPtrArray *unwanted_results;
- QueryData *data;
-} DiffData;
-
-typedef struct {
- gchar *subject;
- TrackerWritebackConsumer *consumer;
-} SubjectAndConsumer;
-
enum {
STATE_IDLE,
STATE_PROCESSING
@@ -77,6 +66,7 @@ static void tracker_writeback_consumer_finalize (GObject *object);
static void tracker_writeback_consumer_constructed (GObject *object);
static gboolean process_queue_cb (gpointer user_data);
+
G_DEFINE_TYPE (TrackerWritebackConsumer, tracker_writeback_consumer, G_TYPE_OBJECT)
static void
@@ -183,49 +173,32 @@ sparql_rdf_types_match (const gchar * const *module_types,
}
static void
-sparql_query_cb_diff (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+sparql_query_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- DiffData *diff_data = user_data;
TrackerWritebackConsumerPrivate *priv;
- TrackerWritebackConsumer *consumer = diff_data->consumer;
- QueryData *data = diff_data->data;
+ TrackerWritebackConsumer *consumer;
+ QueryData *data;
GError *error = NULL;
TrackerSparqlCursor *cursor;
- GPtrArray *unwanted_results = diff_data->unwanted_results;
+ consumer = TRACKER_WRITEBACK_CONSUMER (user_data);
priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
+ data = g_queue_pop_head (priv->process_queue);
cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
if (!error) {
- GPtrArray *results = g_ptr_array_new_with_free_func ((GDestroyNotify) g_strfreev);
+ GPtrArray *results = g_ptr_array_new ();
guint cols = tracker_sparql_cursor_get_n_columns (cursor);
- g_assert (cols >= 2);
-
while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
- gboolean unwanted = FALSE;
- const gchar *predicate = tracker_sparql_cursor_get_string (cursor, 2, NULL);
- guint y;
-
- for (y = 0; y < unwanted_results->len; y++) {
- GStrv unwanted_row = g_ptr_array_index (unwanted_results, y);
- if (g_strcmp0 (unwanted_row[2], predicate) == 0) {
- unwanted = TRUE;
- break;
- }
- }
-
- if (!unwanted) {
- GStrv row = g_new0 (gchar*, cols);
- guint i;
-
- for (i = 0; i < cols; i++)
- row[i] = g_strdup (tracker_sparql_cursor_get_string (cursor, i, NULL));
- g_ptr_array_add (results, row);
- }
+ GStrv row = g_new0 (gchar*, cols);
+ guint i;
+ for (i = 0; i < cols; i++)
+ row[i] = g_strdup (tracker_sparql_cursor_get_string (cursor, i, NULL));
+ g_ptr_array_add (results, row);
}
if (results->len > 0) {
@@ -256,92 +229,24 @@ sparql_query_cb_diff (GObject *object,
g_object_unref (writeback);
}
}
+ g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
} else {
g_message (" No files qualify for updates");
}
- g_ptr_array_unref (results);
+ g_ptr_array_free (results, TRUE);
g_object_unref (cursor);
} else {
g_message (" No files qualify for updates (%s)", error->message);
g_error_free (error);
}
- g_ptr_array_unref (unwanted_results);
g_strfreev (data->rdf_types);
g_slice_free (QueryData, data);
- g_free (diff_data);
priv->idle_id = g_idle_add (process_queue_cb, consumer);
}
static void
-sparql_query_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- SubjectAndConsumer *s_and_c = user_data;
- TrackerWritebackConsumerPrivate *priv;
- QueryData *data;
- GError *error = NULL;
- TrackerSparqlCursor *cursor;
- TrackerWritebackConsumer *consumer = s_and_c->consumer;
-
- priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
- data = g_queue_pop_head (priv->process_queue);
-
- cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
-
- if (!error) {
- GPtrArray *unwanted_results = g_ptr_array_new_with_free_func ((GDestroyNotify) g_strfreev);
- guint cols = tracker_sparql_cursor_get_n_columns (cursor);
- DiffData *diff_data = g_new0 (DiffData, 1);
- gchar *query;
-
- while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
- GStrv row = g_new0 (gchar*, cols);
- guint i;
- for (i = 0; i < cols; i++) {
- row[i] = g_strdup (tracker_sparql_cursor_get_string (cursor, i, NULL));
- }
- g_ptr_array_add (unwanted_results, row);
- }
-
- diff_data->consumer = consumer;
- diff_data->data = data;
- diff_data->unwanted_results = unwanted_results;
-
- query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
- " <%s> ?predicate ?object ; "
- " nie:url ?url ."
- " ?predicate tracker:writeback true . "
- "}",
- s_and_c->subject, s_and_c->subject);
-
- tracker_sparql_connection_query_async (priv->connection,
- query,
- NULL,
- sparql_query_cb_diff,
- diff_data);
-
- g_free (s_and_c->subject);
- g_free (s_and_c);
- g_free (query);
-
- return;
- } else {
- g_message (" No files qualify for updates (%s)", error->message);
- g_error_free (error);
- }
-
- priv->idle_id = g_idle_add (process_queue_cb, consumer);
-
- g_strfreev (data->rdf_types);
- g_slice_free (QueryData, data);
- g_free (s_and_c->subject);
- g_free (s_and_c);
-}
-
-static void
rdf_types_to_uris_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -366,7 +271,6 @@ rdf_types_to_uris_cb (GObject *object,
const gchar *subject;
GArray *rdf_types;
guint i;
- SubjectAndConsumer *s_and_c;
rdf_types = g_array_new (TRUE, TRUE, sizeof (gchar *));
@@ -399,22 +303,18 @@ rdf_types_to_uris_cb (GObject *object,
goto trouble;
}
- query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
- " GRAPH <" TRACKER_MINER_FS_GRAPH_URN "> { <%s> ?predicate ?object . } "
- " <%s> nie:url ?url ."
- " ?predicate tracker:writeback true . "
- "}",
+ query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object { "
+ "<%s> ?predicate ?object ; nie:url ?url . "
+ "?predicate tracker:writeback true . "
+ "FILTER (NOT EXISTS { GRAPH <"TRACKER_MINER_FS_GRAPH_URN"> "
+ "{ <%s> ?predicate ?object } }) } ",
subject, subject, subject);
- s_and_c = g_new0 (SubjectAndConsumer, 1);
- s_and_c->subject = g_strdup (subject);
- s_and_c->consumer = consumer;
-
tracker_sparql_connection_query_async (priv->connection,
query,
NULL,
sparql_query_cb,
- s_and_c);
+ consumer);
g_free (query);
g_object_unref (cursor);
@@ -485,7 +385,6 @@ process_queue_cb (gpointer user_data)
/* Keep "processing" state */
priv->idle_id = 0;
-
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]