[tracker/wip/carlosg/update-perf: 10/18] core: Use statement cache on queries for property values




commit 22130bc39f0f6506cb3fcdb5cb04fd3b9f3062b8
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 50dc9b66e..1e173a23b 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;
@@ -1397,6 +1398,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);
 }
 
@@ -1774,6 +1776,7 @@ get_property_values (TrackerData      *data,
                      TrackerProperty  *property,
                      GError          **error)
 {
+       TrackerDataUpdateBufferGraph *graph;
        const gchar *database;
        GArray *old_values;
 
@@ -1787,23 +1790,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,
@@ -2426,6 +2441,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]