[tracker/lru-stmt-cache] libtracker-data: Set new stmts as tail, not as head



commit 9ab6337664a046040e0e1107bead00b1a85e27eb
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Sep 21 14:30:12 2010 +0200

    libtracker-data: Set new stmts as tail, not as head

 src/libtracker-data/tracker-db-interface-sqlite.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index e4bb71e..0b5a575 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -38,7 +38,8 @@
 
 #include "tracker-db-interface-sqlite.h"
 
-#define TRACKER_STMT_LRU_SIZE	1000
+/* Increase this after testing is done */
+#define TRACKER_STMT_LRU_SIZE	3
 
 struct TrackerDBInterface {
 	GObject parent_instance;
@@ -888,18 +889,21 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 			                      (gpointer) sqlite3_sql (sqlite_stmt),
 			                      stmt);
 
-			if (stmt_lru.size > TRACKER_STMT_LRU_SIZE) {
+			if (stmt_lru.size >= TRACKER_STMT_LRU_SIZE) {
+				TrackerDBStatement *new_head;
 				/* Destroy old stmt_lru.head and fix the ring */
-				stmt->prev = stmt_lru.head->prev;
-				stmt_lru.head->prev->next = stmt;
+				new_head = stmt_lru.head->prev;
+				stmt->prev = new_head;
+				new_head->next = stmt;
 				g_hash_table_remove (db_interface->dynamic_statements,
 				                     (gpointer) sqlite3_sql (stmt_lru.head->stmt));
+				stmt_lru.head = new_head;
 			} else {
 				if (stmt_lru.size == 0) {
 					stmt_lru.head = stmt;
 					stmt_lru.tail = stmt;
 				}
-				/* Put stmt as new head (new least recent used) */
+				/* Put stmt as new tail (new most recent used) */
 				stmt->prev = stmt_lru.head;
 				stmt_lru.head->next = stmt;
 				stmt_lru.size++;
@@ -908,7 +912,7 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 			/* Shared by both of above */
 			stmt_lru.tail->prev = stmt;
 			stmt->next = stmt_lru.tail;
-			stmt_lru.head = stmt;
+			stmt_lru.tail = stmt;
 		}
 	} else {
 		tracker_db_statement_sqlite_reset (stmt);



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