[tracker/wip/carlosg/update-perf: 66/72] core: Keep statement to query resource IDs
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/update-perf: 66/72] core: Keep statement to query resource IDs
- Date: Tue, 30 Aug 2022 15:39:42 +0000 (UTC)
commit fb402b6e3a9d13f9df2ad5635fda361a033cf072
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 20 15:49:49 2022 +0200
core: Keep statement to query resource IDs
This is quite a hot path during updates of already existing resources,
it makes sense to keep the statement around, instead of resorting to
cache lookups.
src/libtracker-sparql/core/tracker-data-update.c | 45 +++++++++++++++++++-----
1 file changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index ad6fcbce9..d6cedd85d 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -93,6 +93,7 @@ struct _TrackerDataUpdateBuffer {
GPtrArray *graphs;
/* Statement to insert in Resource table */
TrackerDBStatement *insert_resource;
+ TrackerDBStatement *query_resource;
/* Array of TrackerDataPropertyEntry */
GArray *properties;
@@ -668,6 +669,7 @@ tracker_data_finalize (GObject *object)
g_clear_pointer (&data->update_buffer.update_log, g_array_unref);
g_clear_pointer (&data->update_buffer.class_updates, g_hash_table_unref);
g_clear_object (&data->update_buffer.insert_resource);
+ g_clear_object (&data->update_buffer.query_resource);
tracker_db_statement_mru_finish (&data->update_buffer.stmt_mru);
g_clear_pointer (&data->insert_callbacks, g_ptr_array_unref);
@@ -887,23 +889,48 @@ query_resource_id (TrackerData *data,
GError **error)
{
TrackerDBInterface *iface;
- TrackerRowid *value, id;
+ TrackerDBStatement *stmt;
+ TrackerRowid *value, id = 0;
+ GError *inner_error = NULL;
+ GArray *res = NULL;
value = g_hash_table_lookup (data->update_buffer.resource_cache, uri);
+ if (value)
+ return *value;
- if (value == NULL) {
+ stmt = data->update_buffer.query_resource;
+ if (!stmt) {
iface = tracker_data_manager_get_writable_db_interface (data->manager);
- id = tracker_data_query_resource_id (data->manager, iface, uri, error);
+ stmt = data->update_buffer.query_resource =
+ tracker_db_interface_create_statement (iface,
+ TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
+ &inner_error,
+ "SELECT ID FROM Resource WHERE Uri = ?");
+ }
- if (id != 0) {
- g_hash_table_insert (data->update_buffer.resource_cache, g_strdup (uri),
- tracker_rowid_copy (&id));
- }
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, uri);
+ res = tracker_db_statement_get_values (stmt,
+ TRACKER_PROPERTY_TYPE_INTEGER,
+ &inner_error);
+ }
- return id;
+ if (G_UNLIKELY (inner_error)) {
+ g_propagate_prefixed_error (error,
+ inner_error,
+ "Querying resource ID:");
+ return 0;
+ }
+
+ if (res && res->len == 1) {
+ id = g_value_get_int64 (&g_array_index (res, GValue, 0));
+ g_hash_table_insert (data->update_buffer.resource_cache, g_strdup (uri),
+ tracker_rowid_copy (&id));
}
- return *value;
+ g_clear_pointer (&res, g_array_unref);
+
+ return id;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]