[tracker/writeback-guarantee: 1/7] tracker-writeback, libtracker-miner: Don't writeback non-strict mined values
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/writeback-guarantee: 1/7] tracker-writeback, libtracker-miner: Don't writeback non-strict mined values
- Date: Mon, 20 Dec 2010 11:05:17 +0000 (UTC)
commit f1524b295828e350393159f4b658f43fe66f6cce
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Dec 16 16:40:50 2010 +0100
tracker-writeback, libtracker-miner: Don't writeback non-strict mined values
The idea here is that since the 'guarantee' branch by Mikael that the
miner might 'guess' non-strict values heuristically. This isn't good
when the writeback service is enabled, as that would mean that the
writeback service could writeback heuristicly guessed values.
To fix this we require that the GRAPH of a value that is to be written
back isn't set to the miner-fs's GRAPH.
src/libtracker-miner/Makefile.am | 3 +-
src/libtracker-miner/tracker-miner-common.h | 25 ++++
src/libtracker-miner/tracker-miner-fs.h | 4 +-
src/tracker-writeback/tracker-writeback-consumer.c | 143 +++++++++++++++++---
4 files changed, 155 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 2d5b3ad..fbcf06f 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -59,7 +59,8 @@ libtracker_minerinclude_HEADERS = \
tracker-network-provider.h \
tracker-password-provider.h \
tracker-storage.h \
- tracker-thumbnailer.h
+ tracker-thumbnailer.h \
+ tracker-miner-common.h
libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
diff --git a/src/libtracker-miner/tracker-miner-common.h b/src/libtracker-miner/tracker-miner-common.h
new file mode 100644
index 0000000..ef792e1
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-common.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_MINER_MINER_COMMON_H__
+#define __LIBTRACKER_MINER_MINER_COMMON_H__
+
+#define TRACKER_MINER_FS_GRAPH_URN "urn:uuid:472ed0cc-40ff-4e37-9c0c-062d78656540"
+
+#endif /* __LIBTRACKER_MINER_MINER_COMMON_H__ */
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 80ce57d..2fb6415 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -31,9 +31,9 @@
#include "tracker-miner-object.h"
-G_BEGIN_DECLS
+#include "tracker-miner-common.h"
-#define TRACKER_MINER_FS_GRAPH_URN "urn:uuid:472ed0cc-40ff-4e37-9c0c-062d78656540"
+G_BEGIN_DECLS
#define TRACKER_TYPE_MINER_FS (tracker_miner_fs_get_type())
#define TRACKER_MINER_FS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_FS, TrackerMinerFS))
diff --git a/src/tracker-writeback/tracker-writeback-consumer.c b/src/tracker-writeback/tracker-writeback-consumer.c
index 2c67f0a..2432706 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.c
+++ b/src/tracker-writeback/tracker-writeback-consumer.c
@@ -30,6 +30,12 @@
#include "tracker-writeback-module.h"
#include "tracker-marshal.h"
+/* Known exception for which linking with libtracker-miner isn't necessary,
+ * include is needed for the TRACKER_MINER_FS_GRAPH_URN define which is
+ * shared between tracker-writeback and tracker-miner-fs */
+
+#include "libtracker-miner/tracker-miner-common.h"
+
#define TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_WRITEBACK_CONSUMER, TrackerWritebackConsumerPrivate))
#define TRACKER_SERVICE "org.freedesktop.Tracker1"
@@ -166,20 +172,26 @@ sparql_rdf_types_match (const gchar * const *module_types,
return FALSE;
}
+typedef struct {
+ TrackerWritebackConsumer *consumer;
+ GPtrArray *unwanted_results;
+ QueryData *data;
+} DiffData;
+
static void
-sparql_query_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+sparql_query_cb_diff (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
+ DiffData *diff_data = user_data;
TrackerWritebackConsumerPrivate *priv;
- TrackerWritebackConsumer *consumer;
- QueryData *data;
+ TrackerWritebackConsumer *consumer = diff_data->consumer;
+ QueryData *data = diff_data->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);
@@ -187,12 +199,29 @@ sparql_query_cb (GObject *object,
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)) {
- 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);
+ 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);
+ }
}
if (results->len > 0) {
@@ -234,12 +263,87 @@ sparql_query_cb (GObject *object,
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);
}
+typedef struct {
+ gchar *subject;
+ TrackerWritebackConsumer *consumer;
+} SubjectAndConsumer;
+
+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 ();
+ guint cols = tracker_sparql_cursor_get_n_columns (cursor);
+
+ 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);
+ }
+
+ if (unwanted_results->len > 0) {
+ DiffData *diff_data = g_new0 (DiffData, 1);
+ gchar *query;
+
+ 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_ptr_array_unref (unwanted_results);
+ }
+ }
+
+ 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,
@@ -265,6 +369,7 @@ 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 *));
@@ -298,17 +403,21 @@ rdf_types_to_uris_cb (GObject *object,
}
query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
- " <%s> ?predicate ?object ; "
- " nie:url ?url ."
- " ?predicate tracker:writeback true "
+ " GRAPH <" TRACKER_MINER_FS_GRAPH_URN "> { <%s> ?predicate ?object . } "
+ " <%s> nie:url ?url ."
+ " ?predicate tracker:writeback true . "
"}",
- subject, subject);
+ 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,
- consumer);
+ s_and_c);
g_free (query);
g_object_unref (cursor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]