[tracker/wip/carlosg/update-perf: 64/72] core: Use statement cache on queries for property values
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/update-perf: 64/72] core: Use statement cache on queries for property values
- Date: Tue, 30 Aug 2022 15:39:42 +0000 (UTC)
commit 414dfa88a760d7bdb8416753a33e019920097025
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 20 11:40:31 2022 +0200
core: Use statement cache on queries for property values
Instead of relying on the internal TrackerDBInterface cache, use a
distinct one in the update machinery, so TrackerProperty objects
can be looked up directly without creating a SQL string.
src/libtracker-sparql/core/tracker-data-update.c | 45 +++++++++++++++++-------
1 file changed, 33 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index dceba867d..ad1c37677 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -122,10 +122,11 @@ struct _TrackerDataUpdateBufferGraph {
TrackerDBStatement *insert_ref;
TrackerDBStatement *update_ref;
TrackerDBStatement *delete_ref;
+ TrackerDBStatementMru values_mru;
};
struct _TrackerDataUpdateBufferResource {
- const TrackerDataUpdateBufferGraph *graph;
+ TrackerDataUpdateBufferGraph *graph;
TrackerRowid id;
gboolean create;
gboolean modified;
@@ -1400,6 +1401,7 @@ graph_buffer_free (TrackerDataUpdateBufferGraph *graph)
g_hash_table_unref (graph->resources);
g_array_unref (graph->refcounts);
g_free (graph->graph);
+ tracker_db_statement_mru_finish (&graph->values_mru);
g_slice_free (TrackerDataUpdateBufferGraph, graph);
}
@@ -1777,6 +1779,7 @@ get_property_values (TrackerData *data,
TrackerProperty *property,
GError **error)
{
+ TrackerDataUpdateBufferGraph *graph;
const gchar *database;
GArray *old_values;
@@ -1790,23 +1793,35 @@ get_property_values (TrackerData *data,
if (old_values != NULL)
return old_values;
- database = data->resource_buffer->graph->graph ?
- data->resource_buffer->graph->graph : "main";
+ graph = data->resource_buffer->graph;
+ database = graph->graph ? graph->graph : "main";
if (!data->resource_buffer->create) {
- TrackerDBInterface *iface;
TrackerDBStatement *stmt;
- const gchar *table_name;
- const gchar *field_name;
- table_name = tracker_property_get_table_name (property);
- field_name = tracker_property_get_name (property);
+ stmt = tracker_db_statement_mru_lookup (&graph->values_mru, property);
- iface = tracker_data_manager_get_writable_db_interface (data->manager);
+ if (stmt) {
+ tracker_db_statement_mru_update (&graph->values_mru, stmt);
+ g_object_ref (stmt);
+ } else {
+ TrackerDBInterface *iface;
+ const gchar *table_name;
+ const gchar *field_name;
+
+ table_name = tracker_property_get_table_name (property);
+ field_name = tracker_property_get_name (property);
+
+ iface = tracker_data_manager_get_writable_db_interface (data->manager);
+ stmt = tracker_db_interface_create_vstatement (iface,
TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, error,
+ "SELECT \"%s\" FROM \"%s\".\"%s\"
WHERE ID = ?",
+ field_name, database, table_name);
+ if (!stmt)
+ return NULL;
+
+ tracker_db_statement_mru_insert (&graph->values_mru, property, stmt);
+ }
- stmt = tracker_db_interface_create_vstatement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
error,
- "SELECT \"%s\" FROM \"%s\".\"%s\" WHERE ID =
?",
- field_name, database, table_name);
if (stmt) {
tracker_db_statement_bind_int (stmt, 0, data->resource_buffer->id);
old_values = tracker_db_statement_get_values (stmt,
@@ -2431,6 +2446,12 @@ ensure_graph_buffer (TrackerDataUpdateBuffer *buffer,
graph_buffer->resources =
g_hash_table_new_full (tracker_rowid_hash, tracker_rowid_equal, NULL,
(GDestroyNotify) resource_buffer_free);
+
+ tracker_db_statement_mru_init (&graph_buffer->values_mru, 20,
+ g_direct_hash,
+ g_direct_equal,
+ NULL);
+
g_ptr_array_add (buffer->graphs, graph_buffer);
return graph_buffer;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]