[tracker/lru-stmt-cache] libtracker-data: Different LRU-cache for INSERT/DELETE v. SELECT



commit a7fa904cb033e8e38370bc58260c36d8cf0ad0d0
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Sep 22 13:23:30 2010 +0200

    libtracker-data: Different LRU-cache for INSERT/DELETE v. SELECT

 src/libtracker-data/libtracker-data.vapi          |    9 ++-
 src/libtracker-data/tracker-data-manager.c        |   24 ++--
 src/libtracker-data/tracker-data-query.c          |    4 +-
 src/libtracker-data/tracker-data-update.c         |   40 ++++---
 src/libtracker-data/tracker-db-interface-sqlite.c |   26 +++--
 src/libtracker-data/tracker-db-interface.h        |  134 +++++++++++----------
 src/libtracker-data/tracker-db-manager.c          |    2 +-
 src/libtracker-data/tracker-sparql-pattern.vala   |    8 +-
 src/libtracker-data/tracker-sparql-query.vala     |    2 +-
 9 files changed, 138 insertions(+), 111 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 067a984..61b1b42 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -34,10 +34,17 @@ namespace Tracker {
 		INTERRUPTED
 	}
 
+	[CCode (cprefix = "TRACKER_DB_STATEMENT_CACHE_TYPE_", cheader_filename = "libtracker-data/tracker-db-interface.h")]
+	public enum DBStatementCacheType {
+		SELECT,
+		UPDATE,
+		NONE
+	}
+
 	[CCode (cheader_filename = "libtracker-data/tracker-db-interface.h")]
 	public interface DBInterface : GLib.Object {
 		[PrintfFormat]
-		public abstract DBStatement create_statement (bool cache_stmt, ...) throws DBInterfaceError;
+		public abstract DBStatement create_statement (DBStatementCacheType cache_type, ...) throws DBInterfaceError;
 	}
 
 	[CCode (cheader_filename = "libtracker-data/tracker-data-update.h")]
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index f1a2db9..74d687d 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1445,7 +1445,7 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
 	TrackerDBCursor *cursor;
 	GError *error = NULL;
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:subClassOf\") "
 	                                              "FROM \"rdfs:Class_rdfs:subClassOf\" "
 	                                              "WHERE ID = (SELECT ID FROM Resource WHERE Uri = ?)");
@@ -1483,7 +1483,7 @@ class_add_domain_indexes_from_db (TrackerDBInterface *iface,
 	TrackerDBCursor *cursor;
 	GError *error = NULL;
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:domainIndex\") "
 	                                              "FROM \"rdfs:Class_tracker:domainIndex\" "
 	                                              "WHERE ID = (SELECT ID FROM Resource WHERE Uri = ?)");
@@ -1521,7 +1521,7 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
 	TrackerDBCursor *cursor;
 	GError *error = NULL;
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:subPropertyOf\") "
 	                                              "FROM \"rdf:Property_rdfs:subPropertyOf\" "
 	                                              "WHERE ID = (SELECT ID FROM Resource WHERE Uri = ?)");
@@ -1560,7 +1560,7 @@ db_get_static_data (TrackerDBInterface *iface)
 	guint n_classes, i;
 	GError *error = NULL;
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Ontology\".ID), "
 	                                              "\"nao:lastModified\" "
 	                                              "FROM \"tracker:Ontology\"");
@@ -1598,7 +1598,7 @@ db_get_static_data (TrackerDBInterface *iface)
 		g_clear_error (&error);
 	}
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Namespace\".ID), "
 	                                              "\"tracker:prefix\" "
 	                                              "FROM \"tracker:Namespace\"");
@@ -1636,7 +1636,7 @@ db_get_static_data (TrackerDBInterface *iface)
 		g_clear_error (&error);
 	}
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT \"rdfs:Class\".ID, "
 	                                              "(SELECT Uri FROM Resource WHERE ID = \"rdfs:Class\".ID), "
 	                                              "\"tracker:notify\" "
@@ -1690,7 +1690,7 @@ db_get_static_data (TrackerDBInterface *iface)
 			if (!g_str_has_prefix (tracker_class_get_name (class), "xsd:") &&
 			    (tracker_db_manager_get_flags () & TRACKER_DB_MANAGER_READONLY) == 0) {
 				/* update statistics */
-				stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 				                                              "SELECT COUNT(1) FROM \"%s\"",
 				                                              tracker_class_get_name (class));
 
@@ -1718,7 +1718,7 @@ db_get_static_data (TrackerDBInterface *iface)
 		g_clear_error (&error);
 	}
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT \"rdf:Property\".ID, (SELECT Uri FROM Resource WHERE ID = \"rdf:Property\".ID), "
 	                                              "(SELECT Uri FROM Resource WHERE ID = \"rdfs:domain\"), "
 	                                              "(SELECT Uri FROM Resource WHERE ID = \"rdfs:range\"), "
@@ -1901,7 +1901,7 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
 	TrackerDBStatement *stmt;
 	GError *error = NULL;
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &error,
 	                                              "INSERT "
 	                                              "INTO Resource "
 	                                              "(ID, Uri) "
@@ -2692,7 +2692,7 @@ get_new_service_id (TrackerDBInterface *iface)
 
 	iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT MAX(ID) AS A FROM Resource");
 
 	if (stmt) {
@@ -2975,7 +2975,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		 * for all the ontology files in ontologies_dir whether the last-modified
 		 * has changed since we dealt with the file last time. */
 
-		stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 		        "SELECT Resource.Uri, \"rdfs:Resource\".\"nao:lastModified\" FROM \"tracker:Ontology\""
 		        "INNER JOIN Resource ON Resource.ID = \"tracker:Ontology\".ID "
 		        "INNER JOIN \"rdfs:Resource\" ON \"tracker:Ontology\".ID = \"rdfs:Resource\".ID");
@@ -3072,7 +3072,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 			if (update_nao) {
 				/* Update the nao:lastModified in the database */
-				stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &error,
 				        "UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
 				        "WHERE \"rdfs:Resource\".ID = "
 				        "(SELECT Resource.ID FROM Resource INNER JOIN \"rdfs:Resource\" "
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 6165608..9e5347a 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -47,7 +47,7 @@ tracker_data_query_rdf_type (gint id)
 
 	iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") "
 	                                              "FROM \"rdfs:Resource_rdf:type\" "
 	                                              "WHERE ID = ?");
@@ -106,7 +106,7 @@ tracker_data_query_resource_id (const gchar *uri)
 
 	iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT ID FROM Resource WHERE Uri = ?");
 
 	if (stmt) {
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index a124f6e..1f613e1 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -344,7 +344,7 @@ tracker_data_update_get_new_service_id (void)
 
 	iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT MAX(ID) AS A FROM Resource");
 
 	if (stmt) {
@@ -389,7 +389,7 @@ tracker_data_update_get_next_modseq (void)
 
 	temp_iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (temp_iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (temp_iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT MAX(\"tracker:modified\") AS A FROM \"rdfs:Resource\"");
 
 	if (stmt) {
@@ -565,7 +565,7 @@ ensure_resource_id (const gchar *uri,
 		iface = tracker_db_manager_get_db_interface ();
 
 		id = tracker_data_update_get_new_service_id ();
-		stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &error,
 		                                              "INSERT INTO Resource (ID, Uri) VALUES (?, ?)");
 
 		if (stmt) {
@@ -661,12 +661,12 @@ tracker_data_resource_buffer_flush (GError **error)
 
 				if (table->delete_value) {
 					/* delete rows for multiple value properties */
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 					                                              "DELETE FROM \"%s\" WHERE ID = ? AND \"%s\" = ?",
 					                                              table_name,
 					                                              property->name);
 				} else if (property->date_time) {
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 					                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:localDate\", \"%s:localTime\", \"%s:graph\") VALUES (?, ?, ?, ?, ?)",
 					                                              table_name,
 					                                              property->name,
@@ -674,7 +674,7 @@ tracker_data_resource_buffer_flush (GError **error)
 					                                              property->name,
 					                                              property->name);
 				} else {
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 					                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:graph\") VALUES (?, ?, ?)",
 					                                              table_name,
 					                                              property->name,
@@ -708,7 +708,7 @@ tracker_data_resource_buffer_flush (GError **error)
 		} else {
 			if (table->delete_row) {
 				/* remove entry from rdf:type table */
-				stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 				                                              "DELETE FROM \"rdfs:Resource_rdf:type\" WHERE ID = ? AND \"rdf:type\" = ?");
 
 				if (stmt) {
@@ -728,7 +728,7 @@ tracker_data_resource_buffer_flush (GError **error)
 				}
 
 				/* remove row from class table */
-				stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 				                                              "DELETE FROM \"%s\" WHERE ID = ?", table_name);
 
 				if (stmt) {
@@ -748,7 +748,7 @@ tracker_data_resource_buffer_flush (GError **error)
 			if (table->insert) {
 				if (strcmp (table_name, "rdfs:Resource") == 0) {
 					/* ensure we have a row for the subject id */
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 						                                      "INSERT OR IGNORE INTO \"%s\" (ID, \"tracker:added\", \"tracker:modified\", Available) VALUES (?, ?, ?, 1)",
 						                                      table_name);
 
@@ -762,7 +762,7 @@ tracker_data_resource_buffer_flush (GError **error)
 					}
 				} else {
 					/* ensure we have a row for the subject id */
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 						                                      "INSERT OR IGNORE INTO \"%s\" (ID) VALUES (?)",
 						                                      table_name);
 
@@ -803,7 +803,7 @@ tracker_data_resource_buffer_flush (GError **error)
 
 			g_string_append (sql, " WHERE ID = ?");
 
-			stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+			stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
 			                                              "%s", sql->str);
 			g_string_free (sql, TRUE);
 
@@ -1203,7 +1203,7 @@ get_property_values (TrackerProperty *property)
 
 		iface = tracker_db_manager_get_db_interface ();
 
-		stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 		                                              "SELECT \"%s\" FROM \"%s\" WHERE ID = ?",
 		                                              field_name, table_name);
 
@@ -1608,7 +1608,7 @@ cache_delete_resource_type (TrackerClass *class,
 
 	/* retrieve all subclasses we need to remove from the subject
 	 * before we can remove the class specified as object of the statement */
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:Class_rdfs:subClassOf\".ID) "
 	                                              "FROM \"rdfs:Resource_rdf:type\" INNER JOIN \"rdfs:Class_rdfs:subClassOf\" ON (\"rdf:type\" = \"rdfs:Class_rdfs:subClassOf\".ID) "
 	                                              "WHERE \"rdfs:Resource_rdf:type\".ID = ? AND \"rdfs:subClassOf\" = (SELECT ID FROM Resource WHERE Uri = ?)");
@@ -2346,7 +2346,7 @@ tracker_data_delete_resource_description (const gchar *graph,
 
 	/* DROP GRAPH <url> - url here is nie:url */
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &actual_error,
 	                                              "SELECT ID, (SELECT Uri FROM Resource WHERE ID = \"nie:DataObject\".ID) FROM \"nie:DataObject\" WHERE \"nie:DataObject\".\"nie:url\" = ?");
 
 	if (stmt) {
@@ -2372,7 +2372,7 @@ tracker_data_delete_resource_description (const gchar *graph,
 
 	properties = tracker_ontologies_get_properties (&n_props);
 
-	stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error,
+	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &actual_error,
 	                                              "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
 
 	if (stmt) {
@@ -2429,7 +2429,8 @@ tracker_data_delete_resource_description (const gchar *graph,
 			single_result = NULL;
 			if (!first) {
 				g_string_append_printf (sql, " FROM \"%s\" WHERE ID = ?", tracker_class_get_name (class));
-				stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error, "%s", sql->str);
+				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
+				                                              &actual_error, "%s", sql->str);
 
 				if (stmt) {
 					tracker_db_statement_bind_int (stmt, 0, resource_id);
@@ -2494,7 +2495,8 @@ tracker_data_delete_resource_description (const gchar *graph,
 					                        " FROM \"%s\" WHERE ID = ?",
 					                        tracker_property_get_table_name (property));
 
-					stmt = tracker_db_interface_create_statement (iface, TRUE, &actual_error, "%s", sql->str);
+					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
+					                                              &actual_error, "%s", sql->str);
 
 					if (stmt) {
 						tracker_db_statement_bind_int (stmt, 0, resource_id);
@@ -2726,7 +2728,7 @@ ontology_transaction_end (GList *ontology_queue,
 			 * db. See tracker-data-manager.c for more info. */
 			last_mod = (gint) tracker_ontology_get_last_modified (ontology);
 
-			stmt = tracker_db_interface_create_statement (iface, TRUE, &error,
+			stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &error,
 			        "UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
 			        "WHERE \"rdfs:Resource\".ID = "
 			        "(SELECT Resource.ID FROM Resource INNER JOIN \"rdfs:Resource\" "
@@ -2834,7 +2836,7 @@ tracker_data_replay_journal (GHashTable          *classes,
 
 			iface = tracker_db_manager_get_db_interface ();
 
-			stmt = tracker_db_interface_create_statement (iface, TRUE, &new_error,
+			stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &new_error,
 					                              "INSERT "
 					                              "INTO Resource "
 					                              "(ID, Uri) "
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 1c6b24c..ba10f6b 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -69,7 +69,8 @@ struct TrackerDBInterface {
 	gboolean pending;
 	GAsyncReadyCallback outstanding_callback;
 
-	TrackerDBStatementLru stmt_lru;
+	TrackerDBStatementLru select_stmt_lru;
+	TrackerDBStatementLru update_stmt_lru;
 };
 
 struct TrackerDBInterfaceClass {
@@ -825,13 +826,13 @@ add_row (TrackerDBResultSet *result_set,
 
 
 TrackerDBStatement *
-tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
-                                       gboolean             cache_stmt,
-                                       GError             **error,
-                                       const gchar         *query,
+tracker_db_interface_create_statement (TrackerDBInterface           *db_interface,
+                                       TrackerDBStatementCacheType   cache_type,
+                                       GError                      **error,
+                                       const gchar                  *query,
                                        ...)
 {
-	TrackerDBStatementLru *stmt_lru = &db_interface->stmt_lru;
+	TrackerDBStatementLru *stmt_lru;
 	TrackerDBStatement *stmt;
 	va_list args;
 	gchar *full_query;
@@ -843,13 +844,20 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 	full_query = g_strdup_vprintf (query, args);
 	va_end (args);
 
-	if (cache_stmt) {
+	if (cache_type != TRACKER_DB_STATEMENT_CACHE_TYPE_NONE) {
 		stmt = g_hash_table_lookup (db_interface->dynamic_statements, full_query);
 
 		if (stmt && stmt->stmt_is_sunk) {
 			/* prepared statement is still in use, create new one */
 			stmt = NULL;
 		}
+
+		if (cache_type == TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE) {
+			stmt_lru = &db_interface->update_stmt_lru;
+		} else {
+			stmt_lru = &db_interface->select_stmt_lru;
+		}
+
 	} else {
 		stmt = NULL;
 	}
@@ -884,7 +892,7 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 
 		stmt = tracker_db_statement_sqlite_new (db_interface, sqlite_stmt);
 
-		if (cache_stmt) {
+		if (cache_type != TRACKER_DB_STATEMENT_CACHE_TYPE_NONE) {
 			/* use replace instead of insert to make sure we store the string that
 			   belongs to the right sqlite statement to ensure the lifetime of the string
 			   matches the statement */
@@ -938,7 +946,7 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 
 	g_free (full_query);
 
-	return cache_stmt ? g_object_ref (stmt) : stmt;
+	return (cache_type != TRACKER_DB_STATEMENT_CACHE_TYPE_NONE) ? g_object_ref (stmt) : stmt;
 }
 
 static TrackerDBResultSet *
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index 4668a14..f8f5b30 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -69,6 +69,12 @@ typedef enum {
 	TRACKER_DB_INTERRUPTED
 } TrackerDBInterfaceError;
 
+typedef enum {
+	TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
+	TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
+	TRACKER_DB_STATEMENT_CACHE_TYPE_NONE
+} TrackerDBStatementCacheType;
+
 typedef struct TrackerDBInterface      TrackerDBInterface;
 typedef struct TrackerDBInterfaceClass TrackerDBInterfaceClass;
 typedef struct TrackerDBStatement      TrackerDBStatement;
@@ -87,80 +93,80 @@ GType                   tracker_db_cursor_get_type              (void);
 GType                   tracker_db_result_set_get_type          (void);
 
 /* Functions to create queries/procedures */
-TrackerDBStatement *    tracker_db_interface_create_statement   (TrackerDBInterface   *interface,
-                                                                 gboolean              cache_stmt,
-                                                                 GError              **error,
-                                                                 const gchar          *query,
+TrackerDBStatement *    tracker_db_interface_create_statement   (TrackerDBInterface          *interface,
+                                                                 TrackerDBStatementCacheType  cache_type,
+                                                                 GError                     **error,
+                                                                 const gchar                 *query,
                                                                  ...) G_GNUC_PRINTF (4, 5);
-TrackerDBResultSet *    tracker_db_interface_execute_vquery     (TrackerDBInterface   *interface,
-                                                                 GError              **error,
-                                                                 const gchar          *query,
-                                                                 va_list               args);
-TrackerDBResultSet *    tracker_db_interface_execute_query      (TrackerDBInterface   *interface,
-                                                                 GError              **error,
-                                                                 const gchar          *query,
+TrackerDBResultSet *    tracker_db_interface_execute_vquery     (TrackerDBInterface          *interface,
+                                                                 GError                     **error,
+                                                                 const gchar                 *query,
+                                                                 va_list                      args);
+TrackerDBResultSet *    tracker_db_interface_execute_query      (TrackerDBInterface          *interface,
+                                                                 GError                     **error,
+                                                                 const gchar                 *query,
                                                                   ...) G_GNUC_PRINTF (3, 4);
 
-gboolean                tracker_db_interface_start_transaction  (TrackerDBInterface  *interface);
-gboolean                tracker_db_interface_end_db_transaction (TrackerDBInterface  *interface);
-void                    tracker_db_statement_bind_double        (TrackerDBStatement  *stmt,
-                                                                 int                  index,
-                                                                 double               value);
-void                    tracker_db_statement_bind_int           (TrackerDBStatement  *stmt,
-                                                                 int                  index,
-                                                                 gint64               value);
-void                    tracker_db_statement_bind_null          (TrackerDBStatement  *stmt,
-                                                                 int                  index);
-void                    tracker_db_statement_bind_text          (TrackerDBStatement  *stmt,
-                                                                 int                  index,
-                                                                 const gchar         *value);
-TrackerDBResultSet *    tracker_db_statement_execute            (TrackerDBStatement  *stmt,
-                                                                 GError             **error);
-TrackerDBCursor *       tracker_db_statement_start_cursor       (TrackerDBStatement  *stmt,
-                                                                 GError             **error);
-TrackerDBCursor *       tracker_db_statement_start_sparql_cursor(TrackerDBStatement  *stmt,
-                                                                 TrackerPropertyType *types,
-                                                                 gint                 n_types,
-                                                                 GError             **error);
+gboolean                tracker_db_interface_start_transaction  (TrackerDBInterface         *interface);
+gboolean                tracker_db_interface_end_db_transaction (TrackerDBInterface         *interface);
+void                    tracker_db_statement_bind_double        (TrackerDBStatement         *stmt,
+                                                                 int                         index,
+                                                                 double                      value);
+void                    tracker_db_statement_bind_int           (TrackerDBStatement         *stmt,
+                                                                 int                         index,
+                                                                 gint64                      value);
+void                    tracker_db_statement_bind_null          (TrackerDBStatement         *stmt,
+                                                                 int                         index);
+void                    tracker_db_statement_bind_text          (TrackerDBStatement         *stmt,
+                                                                 int                         index,
+                                                                 const gchar                *value);
+TrackerDBResultSet *    tracker_db_statement_execute            (TrackerDBStatement         *stmt,
+                                                                 GError                    **error);
+TrackerDBCursor *       tracker_db_statement_start_cursor       (TrackerDBStatement         *stmt,
+                                                                 GError                    **error);
+TrackerDBCursor *       tracker_db_statement_start_sparql_cursor(TrackerDBStatement         *stmt,
+                                                                 TrackerPropertyType        *types,
+                                                                 gint                        n_types,
+                                                                 GError                    **error);
 
 /* Semi private TrackerDBResultSet functions */
-TrackerDBResultSet *    _tracker_db_result_set_new              (guint                cols);
-void                    _tracker_db_result_set_append           (TrackerDBResultSet  *result_set);
-void                    _tracker_db_result_set_set_value        (TrackerDBResultSet  *result_set,
-                                                                 guint                column,
-                                                                 const GValue        *value);
-void                    _tracker_db_result_set_get_value        (TrackerDBResultSet  *result_set,
-                                                                 guint                column,
-                                                                 GValue              *value);
+TrackerDBResultSet *    _tracker_db_result_set_new              (guint                       cols);
+void                    _tracker_db_result_set_append           (TrackerDBResultSet         *result_set);
+void                    _tracker_db_result_set_set_value        (TrackerDBResultSet         *result_set,
+                                                                 guint                       column,
+                                                                 const GValue               *value);
+void                    _tracker_db_result_set_get_value        (TrackerDBResultSet         *result_set,
+                                                                 guint                       column,
+                                                                 GValue                     *value);
 
 /* Functions to deal with the resultset */
-void                    tracker_db_result_set_get               (TrackerDBResultSet  *result_set,
+void                    tracker_db_result_set_get               (TrackerDBResultSet         *result_set,
                                                                  ...);
-void                    tracker_db_result_set_rewind            (TrackerDBResultSet  *result_set);
-gboolean                tracker_db_result_set_iter_next         (TrackerDBResultSet  *result_set);
-guint                   tracker_db_result_set_get_n_columns     (TrackerDBResultSet  *result_set);
-guint                   tracker_db_result_set_get_n_rows        (TrackerDBResultSet  *result_set);
+void                    tracker_db_result_set_rewind            (TrackerDBResultSet         *result_set);
+gboolean                tracker_db_result_set_iter_next         (TrackerDBResultSet         *result_set);
+guint                   tracker_db_result_set_get_n_columns     (TrackerDBResultSet         *result_set);
+guint                   tracker_db_result_set_get_n_rows        (TrackerDBResultSet         *result_set);
 
 /* Functions to deal with a cursor */
-void                    tracker_db_cursor_rewind                (TrackerDBCursor     *cursor);
-gboolean                tracker_db_cursor_iter_next             (TrackerDBCursor     *cursor,
-                                                                 GCancellable        *cancellable,
-                                                                 GError             **error);
-guint                   tracker_db_cursor_get_n_columns         (TrackerDBCursor     *cursor);
-const gchar*            tracker_db_cursor_get_variable_name     (TrackerDBCursor     *cursor,
-                                                                 guint                column);
-TrackerSparqlValueType  tracker_db_cursor_get_value_type        (TrackerDBCursor     *cursor,
-                                                                 guint                column);
-void                    tracker_db_cursor_get_value             (TrackerDBCursor     *cursor,
-                                                                 guint                column,
-                                                                 GValue              *value);
-const gchar*            tracker_db_cursor_get_string            (TrackerDBCursor     *cursor,
-                                                                 guint                column,
-                                                                 glong               *length);
-gint64                  tracker_db_cursor_get_int               (TrackerDBCursor     *cursor,
-                                                                 guint                column);
-gdouble                 tracker_db_cursor_get_double            (TrackerDBCursor     *cursor,
-                                                                 guint                column);
+void                    tracker_db_cursor_rewind                (TrackerDBCursor            *cursor);
+gboolean                tracker_db_cursor_iter_next             (TrackerDBCursor            *cursor,
+                                                                 GCancellable               *cancellable,
+                                                                 GError                    **error);
+guint                   tracker_db_cursor_get_n_columns         (TrackerDBCursor            *cursor);
+const gchar*            tracker_db_cursor_get_variable_name     (TrackerDBCursor            *cursor,
+                                                                 guint                       column);
+TrackerSparqlValueType  tracker_db_cursor_get_value_type        (TrackerDBCursor            *cursor,
+                                                                 guint                       column);
+void                    tracker_db_cursor_get_value             (TrackerDBCursor            *cursor,
+                                                                 guint                       column,
+                                                                 GValue                     *value);
+const gchar*            tracker_db_cursor_get_string            (TrackerDBCursor            *cursor,
+                                                                 guint                       column,
+                                                                 glong                      *length);
+gint64                  tracker_db_cursor_get_int               (TrackerDBCursor            *cursor,
+                                                                 guint                       column);
+gdouble                 tracker_db_cursor_get_double            (TrackerDBCursor            *cursor,
+                                                                 guint                       column);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 122019c..9df44e9 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -895,7 +895,7 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 
 				loaded = TRUE;
 
-				stmt = tracker_db_interface_create_statement (dbs[i].iface, FALSE, NULL,
+				stmt = tracker_db_interface_create_statement (dbs[i].iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, NULL,
 				                                              "PRAGMA integrity_check(1)");
 
 				if (stmt) {
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index 8435896..f61e192 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -37,7 +37,9 @@ namespace Tracker.Sparql {
 					DBResultSet result_set = null;
 					if (subject_id > 0) {
 						var iface = DBManager.get_db_interface ();
-						var stmt = iface.create_statement (true, "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
+						var stmt = iface.create_statement (DBStatementCacheType.SELECT,
+						                                   "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
+						                                   "FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
 						stmt.bind_int (0, subject_id);
 						result_set = stmt.execute ();
 					}
@@ -84,7 +86,9 @@ namespace Tracker.Sparql {
 					var object_id = Data.query_resource_id (object);
 
 					var iface = DBManager.get_db_interface ();
-					var stmt = iface.create_statement (true, "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
+					var stmt = iface.create_statement (DBStatementCacheType.SELECT,
+					                                   "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
+					                                   "FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
 					stmt.bind_int (0, object_id);
 					var result_set = stmt.execute ();
 
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 9eed70e..082ade2 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -489,7 +489,7 @@ public class Tracker.Sparql.Query : Object {
 
 	DBStatement prepare_for_exec (string sql) throws DBInterfaceError, Sparql.Error, DateError {
 		var iface = DBManager.get_db_interface ();
-		var stmt = iface.create_statement (!has_regex, "%s", sql);
+		var stmt = iface.create_statement (has_regex ? DBStatementCacheType.NONE : DBStatementCacheType.SELECT, "%s", sql);
 
 		// set literals specified in query
 		int i = 0;



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