[tracker/wip/carlosg/update-perf: 47/65] core: Add fast path to look up class/property URIs




commit 89e0af5d821794a419c4c8b684938c832ae659a8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 18 20:13:32 2022 +0200

    core: Add fast path to look up class/property URIs
    
    We already have the data in memory, so use that instead of querying the
    database for these. If the URI does not turn out to be a class/property
    one, the database lookup is performed.

 src/libtracker-sparql/core/tracker-data-update.c | 25 +++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index f21c24a6d..740a29d39 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -860,7 +860,9 @@ tracker_data_update_ensure_resource (TrackerData  *data,
        TrackerDBStatement *stmt = NULL;
        GError *inner_error = NULL;
        gchar *key;
-       TrackerRowid *value, id;
+       TrackerRowid *value, id = 0;
+       TrackerOntologies *ontologies;
+       TrackerClass *class;
 
        value = g_hash_table_lookup (data->update_buffer.resource_cache, uri);
 
@@ -868,6 +870,27 @@ tracker_data_update_ensure_resource (TrackerData  *data,
                return *value;
        }
 
+       ontologies = tracker_data_manager_get_ontologies (data->manager);
+       class = tracker_ontologies_get_class_by_uri (ontologies, uri);
+
+       /* Fast path, look up classes/properties directly */
+       if (class) {
+               id = tracker_class_get_id (class);
+       } else {
+               TrackerProperty *property;
+
+               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
+               if (property)
+                       id = tracker_property_get_id (property);
+       }
+
+       if (id != 0) {
+               g_hash_table_insert (data->update_buffer.resource_cache,
+                                    g_strdup (uri),
+                                    tracker_rowid_copy (&id));
+               return id;
+       }
+
        db_manager = tracker_data_manager_get_db_manager (data->manager);
        db_flags = tracker_db_manager_get_flags (db_manager, NULL, NULL);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]