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




commit faf285c29e11997a767c70eaa7fddbfce7e047ea
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 a6c474379..8d1131b77 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -863,7 +863,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);
 
@@ -871,6 +873,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]