[tracker/wip/carlosg/update-perf: 54/61] core: Shuffle query for RDF types of a resource
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/update-perf: 54/61] core: Shuffle query for RDF types of a resource
- Date: Mon, 22 Aug 2022 22:07:44 +0000 (UTC)
commit 61b3ffc0bda70cc349f641d7b50092cc5e705997
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 20 12:17:03 2022 +0200
core: Shuffle query for RDF types of a resource
This is only used in the update machinery, so move it there and keep
the TrackerDBStatement around. This is a very hot path during updates
of already existing resources, so it makes sense to avoid the DB
interface internal caches and SQL query strings for this.
src/libtracker-sparql/core/tracker-data-query.c | 61 ---------------------
src/libtracker-sparql/core/tracker-data-query.h | 5 --
src/libtracker-sparql/core/tracker-data-update.c | 70 +++++++++++++++++++++++-
3 files changed, 68 insertions(+), 68 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-query.c b/src/libtracker-sparql/core/tracker-data-query.c
index bc7413364..7aa563338 100644
--- a/src/libtracker-sparql/core/tracker-data-query.c
+++ b/src/libtracker-sparql/core/tracker-data-query.c
@@ -33,67 +33,6 @@
#include "tracker-ontologies.h"
#include "tracker-sparql.h"
-GPtrArray*
-tracker_data_query_rdf_type (TrackerDataManager *manager,
- const gchar *graph,
- TrackerRowid id,
- GError **error)
-{
- TrackerDBInterface *iface;
- TrackerDBStatement *stmt;
- GArray *classes = NULL;
- GPtrArray *ret = NULL;
- GError *inner_error = NULL;
- TrackerOntologies *ontologies;
- const gchar *class_uri;
- guint i;
-
- iface = tracker_data_manager_get_writable_db_interface (manager);
- ontologies = tracker_data_manager_get_ontologies (manager);
-
- stmt = tracker_db_interface_create_vstatement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&inner_error,
- "SELECT (SELECT Uri FROM Resource WHERE ID =
\"rdf:type\") "
- "FROM \"%s\".\"rdfs:Resource_rdf:type\" "
- "WHERE ID = ?",
- graph ? graph : "main");
-
- if (stmt) {
- tracker_db_statement_bind_int (stmt, 0, id);
- classes = tracker_db_statement_get_values (stmt,
- TRACKER_PROPERTY_TYPE_STRING,
- &inner_error);
- g_object_unref (stmt);
- }
-
- if (classes) {
- ret = g_ptr_array_sized_new (classes->len);
-
- for (i = 0; i < classes->len; i++) {
- TrackerClass *cl;
-
- class_uri = g_value_get_string (&g_array_index (classes, GValue, i));
- cl = tracker_ontologies_get_class_by_uri (ontologies, class_uri);
- if (!cl) {
- g_critical ("Unknown class %s", class_uri);
- continue;
- }
- g_ptr_array_add (ret, cl);
- }
-
- g_array_unref (classes);
- }
-
- if (G_UNLIKELY (inner_error)) {
- g_propagate_prefixed_error (error,
- inner_error,
- "Querying RDF type:");
- g_clear_pointer (&ret, g_ptr_array_unref);
- return NULL;
- }
-
- return ret;
-}
-
gchar *
tracker_data_query_resource_urn (TrackerDataManager *manager,
TrackerDBInterface *iface,
diff --git a/src/libtracker-sparql/core/tracker-data-query.h b/src/libtracker-sparql/core/tracker-data-query.h
index 94d84400d..11f7c6762 100644
--- a/src/libtracker-sparql/core/tracker-data-query.h
+++ b/src/libtracker-sparql/core/tracker-data-query.h
@@ -41,11 +41,6 @@ TrackerDBCursor *tracker_data_query_sparql_cursor (TrackerDataManager *mana
const gchar *query,
GError **error);
-GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *manager,
- const gchar *graph,
- TrackerRowid id,
- GError **error);
-
gboolean tracker_data_query_string_to_value (TrackerDataManager *manager,
const gchar *value,
const gchar *langtag,
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index 1e173a23b..570038b63 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -122,6 +122,7 @@ struct _TrackerDataUpdateBufferGraph {
TrackerDBStatement *insert_ref;
TrackerDBStatement *update_ref;
TrackerDBStatement *delete_ref;
+ TrackerDBStatement *query_rdf_types;
TrackerDBStatementMru values_mru;
};
@@ -813,6 +814,70 @@ log_entry_for_class (TrackerData *data,
g_hash_table_add (data->update_buffer.class_updates, entry_ptr);
}
+static GPtrArray*
+tracker_data_query_rdf_type (TrackerData *data,
+ TrackerDataUpdateBufferGraph *graph,
+ TrackerRowid id,
+ GError **error)
+{
+ TrackerDBInterface *iface;
+ TrackerDBStatement *stmt;
+ GArray *classes = NULL;
+ GPtrArray *ret = NULL;
+ GError *inner_error = NULL;
+ TrackerOntologies *ontologies;
+ const gchar *class_uri;
+ guint i;
+
+ iface = tracker_data_manager_get_writable_db_interface (data->manager);
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
+
+ stmt = graph->query_rdf_types;
+
+ if (!stmt) {
+ stmt = graph->query_rdf_types =
+ tracker_db_interface_create_vstatement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
&inner_error,
+ "SELECT (SELECT Uri FROM Resource WHERE ID =
\"rdf:type\") "
+ "FROM \"%s\".\"rdfs:Resource_rdf:type\" "
+ "WHERE ID = ?",
+ graph->graph ? graph->graph : "main");
+ }
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, id);
+ classes = tracker_db_statement_get_values (stmt,
+ TRACKER_PROPERTY_TYPE_STRING,
+ &inner_error);
+ }
+
+ if (G_UNLIKELY (inner_error)) {
+ g_propagate_prefixed_error (error,
+ inner_error,
+ "Querying RDF type:");
+ return NULL;
+ }
+
+ if (classes) {
+ ret = g_ptr_array_sized_new (classes->len);
+
+ for (i = 0; i < classes->len; i++) {
+ TrackerClass *cl;
+
+ class_uri = g_value_get_string (&g_array_index (classes, GValue, i));
+ cl = tracker_ontologies_get_class_by_uri (ontologies, class_uri);
+ if (!cl) {
+ g_critical ("Unknown class %s", class_uri);
+ continue;
+ }
+ g_ptr_array_add (ret, cl);
+ }
+
+ g_array_unref (classes);
+ }
+
+ return ret;
+}
+
static TrackerRowid
query_resource_id (TrackerData *data,
const gchar *uri,
@@ -1395,6 +1460,7 @@ graph_buffer_free (TrackerDataUpdateBufferGraph *graph)
g_clear_object (&graph->insert_ref);
g_clear_object (&graph->update_ref);
g_clear_object (&graph->delete_ref);
+ g_clear_object (&graph->query_rdf_types);
g_hash_table_unref (graph->resources);
g_array_unref (graph->refcounts);
g_free (graph->graph);
@@ -2492,8 +2558,8 @@ resource_buffer_switch (TrackerData *data,
create = g_hash_table_contains (data->update_buffer.new_resources,
&subject);
if (!create) {
- rdf_types = tracker_data_query_rdf_type (data->manager,
- graph,
+ rdf_types = tracker_data_query_rdf_type (data,
+ graph_buffer,
subject,
&inner_error);
if (!rdf_types) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]