[tracker/wip/carlosg/update-perf: 50/61] core: Decouple FTS updates from previous property value lookups
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/update-perf: 50/61] core: Decouple FTS updates from previous property value lookups
- Date: Mon, 22 Aug 2022 22:07:44 +0000 (UTC)
commit cc2474032efe6d4d87d70c34953be0fe43261445
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 20 18:46:16 2022 +0200
core: Decouple FTS updates from previous property value lookups
Right now, FTS updates do iterate the set of previously looked up
properties in order to find the FTS ones and issue the FTS update.
We want to optimize on fetching the old values for properties, and
FTS is orthogonal to it, so decouple both machineries. As a replacement
keep a list of FTS properties that were modified, so that these are
updated when flushing.
src/libtracker-sparql/core/tracker-data-update.c | 115 ++++++++++-------------
1 file changed, 51 insertions(+), 64 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index 930ade036..25ece7ddd 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -134,7 +134,7 @@ struct _TrackerDataUpdateBufferResource {
/* TrackerClass */
GPtrArray *types;
- gboolean fts_updated;
+ GList *fts_properties;
};
struct _TrackerStatementDelegate {
@@ -1404,6 +1404,7 @@ static void resource_buffer_free (TrackerDataUpdateBufferResource *resource)
{
g_clear_pointer (&resource->predicates, g_hash_table_unref);
+ g_list_free (resource->fts_properties);
g_ptr_array_free (resource->types, TRUE);
resource->types = NULL;
@@ -1420,6 +1421,7 @@ tracker_data_update_buffer_flush (TrackerData *data,
GHashTableIter iter;
GError *actual_error = NULL;
const gchar *database;
+ GList *l;
guint i;
if (data->update_buffer.update_log->len == 0)
@@ -1432,38 +1434,27 @@ tracker_data_update_buffer_flush (TrackerData *data,
g_hash_table_iter_init (&iter, graph->resources);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &resource)) {
- if (resource->fts_updated && !resource->create) {
- TrackerProperty *prop;
- GArray *values;
- GHashTableIter prop_iter;
+ if (resource->fts_properties && !resource->create) {
GPtrArray *properties;
gboolean retval;
- properties = NULL;
+ properties = g_ptr_array_sized_new (8);
database = resource->graph->graph ? resource->graph->graph : "main";
- g_hash_table_iter_init (&prop_iter, resource->predicates);
- while (g_hash_table_iter_next (&prop_iter, (gpointer*) &prop, (gpointer*)
&values)) {
- if (tracker_property_get_fulltext_indexed (prop)) {
- if (!properties)
- properties = g_ptr_array_new ();
-
- g_ptr_array_add (properties, (gpointer)
tracker_property_get_name (prop));
- }
- }
- if (properties) {
- g_ptr_array_add (properties, NULL);
+ for (l = resource->fts_properties; l; l = l->next)
+ g_ptr_array_add (properties, (gpointer) tracker_property_get_name
(l->data));
- retval = tracker_db_interface_sqlite_fts_delete_text (iface,
- database,
- resource->id,
- (const gchar
**) properties->pdata,
- error);
- g_ptr_array_free (properties, TRUE);
+ g_ptr_array_add (properties, NULL);
- if (!retval)
- goto out;
- }
+ retval = tracker_db_interface_sqlite_fts_delete_text (iface,
+ database,
+ resource->id,
+ (const gchar **)
properties->pdata,
+ error);
+ g_ptr_array_free (properties, TRUE);
+
+ if (!retval)
+ goto out;
}
}
}
@@ -1476,38 +1467,27 @@ tracker_data_update_buffer_flush (TrackerData *data,
g_hash_table_iter_init (&iter, graph->resources);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &resource)) {
- if (resource->fts_updated) {
- TrackerProperty *prop;
- GArray *values;
- GHashTableIter prop_iter;
+ if (resource->fts_properties) {
GPtrArray *properties;
gboolean retval;
- properties = NULL;
+ properties = g_ptr_array_sized_new (8);
database = resource->graph->graph ? resource->graph->graph : "main";
- g_hash_table_iter_init (&prop_iter, resource->predicates);
- while (g_hash_table_iter_next (&prop_iter, (gpointer*) &prop, (gpointer*)
&values)) {
- if (tracker_property_get_fulltext_indexed (prop)) {
- if (!properties)
- properties = g_ptr_array_new ();
-
- g_ptr_array_add (properties, (gpointer)
tracker_property_get_name (prop));
- }
- }
- if (properties) {
- g_ptr_array_add (properties, NULL);
+ for (l = resource->fts_properties; l; l = l->next)
+ g_ptr_array_add (properties, (gpointer) tracker_property_get_name
(l->data));
- retval = tracker_db_interface_sqlite_fts_update_text (iface,
- database,
- resource->id,
- (const gchar
**) properties->pdata,
- error);
- g_ptr_array_free (properties, TRUE);
+ g_ptr_array_add (properties, NULL);
- if (!retval)
- goto out;
- }
+ retval = tracker_db_interface_sqlite_fts_update_text (iface,
+ database,
+ resource->id,
+ (const gchar **)
properties->pdata,
+ error);
+ g_ptr_array_free (properties, TRUE);
+
+ if (!retval)
+ goto out;
}
}
@@ -1974,6 +1954,20 @@ maybe_convert_value (TrackerData *data,
return FALSE;
}
+static void
+maybe_append_fts_property (TrackerData *data,
+ TrackerProperty *property)
+{
+ if (!tracker_property_get_fulltext_indexed (property))
+ return;
+
+ if (g_list_find (data->resource_buffer->fts_properties, property))
+ return;
+
+ data->resource_buffer->fts_properties =
+ g_list_prepend (data->resource_buffer->fts_properties, property);
+}
+
static gboolean
cache_insert_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
@@ -2024,8 +2018,7 @@ cache_insert_metadata_decomposed (TrackerData *data,
super_properties = tracker_property_get_super_properties (property);
multiple_values = tracker_property_get_multiple_values (property);
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (property);
+ maybe_append_fts_property (data, property);
while (*super_properties) {
gboolean super_is_multi;
@@ -2040,8 +2033,7 @@ cache_insert_metadata_decomposed (TrackerData *data,
return FALSE;
}
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (*super_properties);
+ maybe_append_fts_property (data, *super_properties);
if (maybe_convert_value (data,
tracker_property_get_data_type (property),
@@ -2165,8 +2157,7 @@ delete_metadata_decomposed (TrackerData *data,
multiple_values = tracker_property_get_multiple_values (property);
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (property);
+ maybe_append_fts_property (data, property);
/* read existing property values */
old_values = get_property_values (data, property, &new_error);
@@ -2331,8 +2322,7 @@ cache_delete_resource_type_full (TrackerData *data,
multiple_values = tracker_property_get_multiple_values (prop);
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (prop);
+ maybe_append_fts_property (data, prop);
old_values = get_property_values (data, prop, error);
if (!old_values)
@@ -2480,7 +2470,6 @@ resource_buffer_switch (TrackerData *data,
resource_buffer->id = subject;
resource_buffer->create = create;
- resource_buffer->fts_updated = FALSE;
if (resource_buffer->create) {
resource_buffer->types = g_ptr_array_new ();
} else {
@@ -2885,8 +2874,7 @@ tracker_data_update_statement (TrackerData *data,
if (!resource_buffer_switch (data, graph, subject, error))
return;
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (predicate);
+ maybe_append_fts_property (data, predicate);
log_entry_for_multi_value_property (data,
TRACKER_LOG_MULTIVALUED_PROPERTY_CLEAR,
@@ -2900,8 +2888,7 @@ tracker_data_update_statement (TrackerData *data,
if (!resource_buffer_switch (data, graph, subject, error))
return;
- data->resource_buffer->fts_updated |=
- tracker_property_get_fulltext_indexed (predicate);
+ maybe_append_fts_property (data, predicate);
if (!delete_single_valued (data, graph, subject, predicate,
!tracker_property_get_multiple_values (predicate),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]