[tracker/journal: 15/21] libtracker-data: STATEMENT_DELETE_ID journal replay performance improvement
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/journal: 15/21] libtracker-data: STATEMENT_DELETE_ID journal replay performance improvement
- Date: Tue, 16 Mar 2010 15:31:28 +0000 (UTC)
commit cdd3a2e80dcdcdd7b4bbae7e9c2033b1db7198f2
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Mar 15 18:10:47 2010 +0100
libtracker-data: STATEMENT_DELETE_ID journal replay performance improvement
src/libtracker-data/tracker-data-update.c | 87 ++++++++++++++---------------
1 files changed, 42 insertions(+), 45 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index c51b51b..8679f86 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1262,7 +1262,8 @@ cache_set_metadata_decomposed (TrackerProperty *property,
static gboolean
delete_metadata_decomposed (TrackerProperty *property,
- const gchar *value,
+ const gchar *value,
+ gint value_id,
GError **error)
{
gboolean multiple_values, fts;
@@ -1294,12 +1295,16 @@ delete_metadata_decomposed (TrackerProperty *property,
return FALSE;
}
- string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, &new_error);
-
- if (new_error) {
- g_free (table_name);
- g_propagate_error (error, new_error);
- return FALSE;
+ if (value) {
+ string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, &new_error);
+ if (new_error) {
+ g_free (table_name);
+ g_propagate_error (error, new_error);
+ return FALSE;
+ }
+ } else {
+ g_value_init (&gvalue, G_TYPE_INT);
+ g_value_set_int (&gvalue, value_id);
}
if (!value_set_remove_value (old_values, &gvalue)) {
@@ -1317,7 +1322,7 @@ delete_metadata_decomposed (TrackerProperty *property,
/* also delete super property values */
super_properties = tracker_property_get_super_properties (property);
while (*super_properties) {
- delete_metadata_decomposed (*super_properties, value, error);
+ delete_metadata_decomposed (*super_properties, value, 0, error);
super_properties++;
}
@@ -1548,7 +1553,7 @@ tracker_data_delete_statement (const gchar *graph,
if (field != NULL) {
gint id;
- change = delete_metadata_decomposed (field, object, error);
+ change = delete_metadata_decomposed (field, object, 0, error);
id = tracker_property_get_id (field);
if (!in_journal_replay && change) {
@@ -2461,31 +2466,6 @@ tracker_data_sync (void)
tracker_db_journal_fsync ();
}
-static gchar *
-query_resource_by_id (gint id)
-{
- TrackerDBCursor *cursor;
- TrackerDBInterface *iface;
- TrackerDBStatement *stmt;
- gchar *uri;
-
- g_return_val_if_fail (id > 0, NULL);
-
- iface = tracker_db_manager_get_db_interface ();
-
- stmt = tracker_db_interface_create_statement (iface,
- "SELECT Uri FROM Resource WHERE ID = ?");
- tracker_db_statement_bind_int (stmt, 0, id);
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
-
- tracker_db_cursor_iter_next (cursor);
- uri = g_strdup (tracker_db_cursor_get_string (cursor, 0));
- g_object_unref (cursor);
-
- return uri;
-}
-
void
tracker_data_replay_journal (GHashTable *classes,
GHashTable *properties)
@@ -2500,9 +2480,8 @@ tracker_data_replay_journal (GHashTable *classes,
tracker_db_journal_reader_init (NULL);
while (tracker_db_journal_reader_next (&journal_error)) {
- GError *error = NULL;
TrackerDBJournalEntryType type;
- const gchar *graph, *subject, *predicate, *object;
+ const gchar *object;
gint graph_id, subject_id, predicate_id, object_id;
type = tracker_db_journal_reader_get_type ();
@@ -2617,7 +2596,7 @@ tracker_data_replay_journal (GHashTable *classes,
g_warning ("Journal replay error: 'class with '%s' not found in the ontology'", object);
}
} else {
- delete_metadata_decomposed (property, object, &new_error);
+ delete_metadata_decomposed (property, object, 0, &new_error);
}
if (new_error) {
@@ -2630,18 +2609,36 @@ tracker_data_replay_journal (GHashTable *classes,
}
} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID) {
+ TrackerClass *class = NULL;
+ TrackerProperty *property;
+
tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
- if (graph_id > 0) {
- graph = query_resource_by_id (graph_id);
+ property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));
+ class = g_hash_table_lookup (classes, GINT_TO_POINTER (object_id));
+
+ if (property && class) {
+
+ resource_buffer_switch (NULL, graph_id, NULL, subject_id);
+
+ if (property == rdf_type) {
+ cache_delete_resource_type (class, NULL, graph_id);
+ } else {
+ GError *new_error = NULL;
+
+ delete_metadata_decomposed (property, NULL, object_id, &new_error);
+
+ if (new_error) {
+ g_warning ("Journal replay error: '%s'", new_error->message);
+ g_error_free (new_error);
+ }
+ }
} else {
- graph = NULL;
+ if (!class)
+ g_warning ("Journal replay error: 'class with ID %d not found in the ontology'", object_id);
+ if (!property)
+ g_warning ("Journal replay error: 'property with ID %d doesn't exist'", predicate_id);
}
- subject = query_resource_by_id (subject_id);
- predicate = query_resource_by_id (predicate_id);
- object = query_resource_by_id (object_id);
-
- tracker_data_delete_statement (graph, subject, predicate, object, &error);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]