[tracker/wip/carlosg/update-perf: 55/65] core: Optimize deletion of classes of a resource
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/update-perf: 55/65] core: Optimize deletion of classes of a resource
- Date: Tue, 23 Aug 2022 09:32:54 +0000 (UTC)
commit 2d7f09eb48a472b40d9ffef8866e93bd07da85de
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Aug 19 18:09:25 2022 +0200
core: Optimize deletion of classes of a resource
Currently the code is exceedengly thorough and issues individual deletes
for every property that is related to the class being deleted. We can take
some shortcuts here, and avoid querying existing values for most cases,
only 2 cases remain where it is necessary to fetch the previous content:
- Properties that have TRACKER_PROPERTY_TYPE_RESOURCE, in order to correctly
change the refcounting of the resource that the property points to.
- Properties that are domain indexes in other classes, since we have to
chain up to those tables with the right value being deleted.
All other situations can do without fetching the previous values for the
property, and for single valued properties, they can even be delegated to
the deletion of the row in the table representing the TrackerClass.
The result is a speedup while deleting entire resources.
src/libtracker-sparql/core/tracker-data-update.c | 69 ++++++++++++++----------
1 file changed, 42 insertions(+), 27 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index 25ece7ddd..484ec87d4 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -2304,14 +2304,21 @@ cache_delete_resource_type_full (TrackerData *data,
}
}
- /* delete all property values */
-
+ /* Delete property values, only properties that:
+ * - Have ?prop rdfs:range rdfs:Resource
+ * - Are domain indexes in other classes
+ *
+ * Do need inspection of the previous content. All multivalued properties
+ * can be cleared through TRACKER_LOG_MULTIVALUED_PROPERTY_CLEAR, and all
+ * values for other single-valued properties will eventually disappear when
+ * deleting the row from the table representing the given TrackerClass.
+ */
properties = tracker_ontologies_get_properties (ontologies, &n_props);
for (p = 0; p < n_props; p++) {
- gboolean multiple_values;
+ gboolean multiple_values;
GArray *old_values;
- gint y;
+ gint y;
prop = properties[p];
@@ -2324,37 +2331,45 @@ cache_delete_resource_type_full (TrackerData *data,
maybe_append_fts_property (data, prop);
- old_values = get_property_values (data, prop, error);
- if (!old_values)
- return FALSE;
+ if (*tracker_property_get_domain_indexes (prop) ||
+ tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ old_values = get_property_values (data, prop, error);
+ if (!old_values)
+ return FALSE;
- for (y = old_values->len - 1; y >= 0 ; y--) {
- GValue *old_gvalue, copy = G_VALUE_INIT;
+ for (y = old_values->len - 1; y >= 0 ; y--) {
+ GValue *old_gvalue, copy = G_VALUE_INIT;
- old_gvalue = &g_array_index (old_values, GValue, y);
- g_value_init (©, G_VALUE_TYPE (old_gvalue));
- g_value_copy (old_gvalue, ©);
+ old_gvalue = &g_array_index (old_values, GValue, y);
+ g_value_init (©, G_VALUE_TYPE (old_gvalue));
+ g_value_copy (old_gvalue, ©);
- value_set_remove_value (old_values, old_gvalue);
+ value_set_remove_value (old_values, old_gvalue);
- if (multiple_values) {
- log_entry_for_multi_value_property (data,
- TRACKER_LOG_MULTIVALUED_PROPERTY_DELETE,
- prop, ©);
- } else {
- log_entry_for_single_value_property (data,
- tracker_property_get_domain (prop),
- prop, NULL);
- }
+ if (!multiple_values) {
+ log_entry_for_single_value_property (data,
+ tracker_property_get_domain
(prop),
+ prop, NULL);
+ }
- if (tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_RESOURCE)
- tracker_data_resource_unref (data, g_value_get_int64 (©),
multiple_values);
+ if (tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_RESOURCE)
+ tracker_data_resource_unref (data, g_value_get_int64 (©),
multiple_values);
- if (!multiple_values)
- delete_property_domain_indexes (data, prop, ©);
+ if (!multiple_values)
+ delete_property_domain_indexes (data, prop, ©);
- g_value_unset (©);
+ g_value_unset (©);
+ }
}
+
+ if (multiple_values) {
+ log_entry_for_multi_value_property (data,
+ TRACKER_LOG_MULTIVALUED_PROPERTY_CLEAR,
+ prop, NULL);
+ }
+
+ if (data->resource_buffer->predicates)
+ g_hash_table_remove (data->resource_buffer->predicates, prop);
}
g_value_init (&gvalue, G_TYPE_INT64);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]