[tracker/tracker-store-queue] Untested port of Turtle importer to tracker-store
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-store-queue] Untested port of Turtle importer to tracker-store
- Date: Thu, 21 May 2009 08:51:04 -0400 (EDT)
commit 4c3040d60aa2438a771e875a081dee947dee4a23
Author: Philip Van Hoof <philip codeminded be>
Date: Thu May 21 14:44:48 2009 +0200
Untested port of Turtle importer to tracker-store
---
src/tracker-store/tracker-resources.c | 153 +++++++++++++++++++++++++--------
1 files changed, 115 insertions(+), 38 deletions(-)
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 814c705..b5361f0 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -34,8 +34,8 @@
#include <libtracker-data/tracker-data-manager.h>
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-data-update.h>
+#include <libtracker-data/tracker-turtle.h>
-#include "tracker-indexer-client.h"
#include "tracker-dbus.h"
#include "tracker-marshal.h"
#include "tracker-resources.h"
@@ -251,6 +251,72 @@ tracker_resources_delete (TrackerResources *self,
}
+
+
+static void
+turtle_commit_callback (gpointer user_data)
+{
+ TrackerResources *object = user_data;
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+ priv->batch_count = 0;
+
+ g_object_unref (object);
+}
+
+static void
+turtle_update_callback (GError *error, gpointer user_data)
+{
+ TrackerResources *object = user_data;
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+ if (++priv->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
+ tracker_store_queue_batch_commit (turtle_commit_callback,
+ g_object_ref (object),
+ NULL);
+ }
+
+ g_object_unref (object);
+}
+
+static void
+process_turtle_file_part (TrackerResources *object)
+{
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+ if (!priv->batch_mode) {
+ priv->batch_mode = TRUE;
+ priv->batch_count = 0;
+ }
+
+ while (tracker_turtle_reader_next ()) {
+
+ gchar *update = g_strdup_printf ("INSERT { <%s> %s \"%s\" }",
+ tracker_turtle_reader_get_subject (),
+ tracker_turtle_reader_get_predicate (),
+ tracker_turtle_reader_get_object ());
+
+ tracker_store_queue_batch_sparql_update (update,
+ turtle_update_callback,
+ g_object_ref (object),
+ NULL);
+
+ g_free (update);
+ }
+
+
+ tracker_store_queue_batch_commit (turtle_commit_callback,
+ g_object_ref (object),
+ NULL);
+}
+
+
void
tracker_resources_load (TrackerResources *object,
const gchar *uri,
@@ -274,9 +340,9 @@ tracker_resources_load (TrackerResources *object,
file = g_file_new_for_uri (uri);
path = g_file_get_path (file);
- org_freedesktop_Tracker_Indexer_turtle_add (tracker_dbus_indexer_get_proxy (),
- path,
- &actual_error);
+ tracker_turtle_reader_init (path, NULL);
+
+ process_turtle_file_part (object);
g_free (path);
g_object_unref (file);
@@ -348,6 +414,22 @@ tracker_resources_sparql_query (TrackerResources *self,
}
+
+
+static void
+s_update_commit_callback (gpointer user_data)
+{
+ TrackerResources *object = user_data;
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+ priv->batch_count = 0;
+ priv->batch_mode = FALSE;
+
+ g_object_unref (object);
+}
+
void
tracker_resources_sparql_update (TrackerResources *self,
const gchar *update,
@@ -365,17 +447,9 @@ tracker_resources_sparql_update (TrackerResources *self,
tracker_dbus_async_return_if_fail (update != NULL, context);
if (priv->batch_mode) {
- /* commit pending batch items */
-
- tracker_store_queue_batch_commit (NULL, NULL, NULL);
-
- /* Question, must we wait here until callback of commit is
- * completed? I guess this just depends on the priority rules
- * of a single update vs. a commit of a batch. If a commit
- * comes first, we don't need to await its callback. Right? */
-
- priv->batch_mode = FALSE;
- priv->batch_count = 0;
+ tracker_store_queue_batch_commit (s_update_commit_callback,
+ g_object_ref (self),
+ NULL);
}
tracker_dbus_request_new (request_id,
@@ -394,6 +468,19 @@ tracker_resources_sparql_update (TrackerResources *self,
}
static void
+update_commit_callback (gpointer user_data)
+{
+ TrackerResources *object = user_data;
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+ priv->batch_count = 0;
+
+ g_object_unref (object);
+}
+
+static void
batch_update_callback (GError *error, gpointer user_data)
{
TrackerDBusMethodInfo *info = user_data;
@@ -411,17 +498,9 @@ batch_update_callback (GError *error, gpointer user_data)
priv = TRACKER_RESOURCES_GET_PRIVATE (info->self);
if (++priv->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
- /* commit pending batch items */
-
- tracker_store_queue_batch_commit (NULL, NULL, NULL);
-
- /* Question, must we wait here until callback of commit is
- * completed? I guess this just depends on the priority rules
- * of a single update vs. a commit of a batch. If a commit
- * comes first, we don't need to await its callback. Right? */
-
- priv->batch_mode = FALSE;
- priv->batch_count = 0;
+ tracker_store_queue_batch_commit (update_commit_callback,
+ g_object_ref (info->self),
+ NULL);
}
dbus_g_method_return (info->context);
@@ -453,12 +532,8 @@ tracker_resources_batch_sparql_update (TrackerResources *self,
update);
if (!priv->batch_mode) {
- /* switch to batch mode
- delays database commits to improve performance */
priv->batch_mode = TRUE;
priv->batch_count = 0;
-
- /* Transaction start is implicit in the queue */
}
info = g_slice_new (TrackerDBusMethodInfo);
@@ -470,16 +545,24 @@ tracker_resources_batch_sparql_update (TrackerResources *self,
tracker_store_queue_batch_sparql_update (update, batch_update_callback,
info, destroy_method_info);
-
}
static void
batch_commit_callback (gpointer user_data)
{
TrackerDBusMethodInfo *info = user_data;
+ TrackerResourcesPrivate *priv;
+
+ priv = TRACKER_RESOURCES_GET_PRIVATE (info->self);
+
+ priv->batch_count = 0;
+ priv->batch_mode = FALSE;
dbus_g_method_return (info->context);
+
tracker_dbus_request_success (info->request_id);
+
+ g_object_unref (info->self);
}
void
@@ -506,17 +589,11 @@ tracker_resources_batch_commit (TrackerResources *self,
info->request_id = request_id;
info->context = context;
+ info->self = g_object_ref (self);
tracker_store_queue_batch_commit (batch_commit_callback, info,
destroy_method_info);
- /* Question, must we wait here until callback of commit is
- * completed? I guess this just depends on the priority rules
- * of a single update vs. a commit of a batch. If a commit
- * comes first, we don't need to await its callback. Right? */
-
- priv->batch_mode = FALSE;
- priv->batch_count = 0;
} else {
dbus_g_method_return (context);
tracker_dbus_request_success (request_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]