From d00a5f737c9e6eae6749015dc87cf68da2b6bd88 Mon Sep 17 00:00:00 2001
From: Stephan Erb <steve-e@h3c.de>
Date: Sun, 27 Dec 2009 16:50:43 +0100
Subject: [PATCH] Create index on the logs table on time instead of on kind.

That way we can search through all logs in constant time instead of having to perform a full table scan.
---
 src/common/check_paths.py |  2 +-
 src/common/defs.py        |  2 +-
 src/common/optparser.py   | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/common/check_paths.py b/src/common/check_paths.py
index 122ab5528f..57fcdf7b8f 100644
--- a/src/common/check_paths.py
+++ b/src/common/check_paths.py
@@ -79,7 +79,7 @@ def create_log_db():
 			subject TEXT
 		);
 
-		CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind);
+		CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC);
 
 		CREATE TABLE caps_cache (
 			hash_method TEXT,
diff --git a/src/common/defs.py b/src/common/defs.py
index bdedcca9a7..11a8d23a6f 100644
--- a/src/common/defs.py
+++ b/src/common/defs.py
@@ -27,7 +27,7 @@
 basedir   = '../'
 localedir = '../po'
 
-version = '0.13.10.0-dev'
+version = '0.13.10.1-dev'
 
 import sys, os.path
 for base in ('.', 'common'):
diff --git a/src/common/optparser.py b/src/common/optparser.py
index 573d9ed078..7b7fe911d5 100644
--- a/src/common/optparser.py
+++ b/src/common/optparser.py
@@ -214,6 +214,8 @@ def update_config(self, old_version, new_version):
 			self.update_config_to_01258()
 		if old < [0, 13, 10, 0] and new >= [0, 13, 10, 0]:
 			self.update_config_to_013100()
+		if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]:
+			self.update_config_to_013101()
 
 		gajim.logger.init_vars()
 		gajim.config.set('version', new_version)
@@ -857,4 +859,25 @@ def update_config_to_013100(self):
 		con.close()
 		gajim.config.set('version', '0.13.10.0')
 
+	def update_config_to_013101(self):
+		back = os.getcwd()
+		os.chdir(logger.LOG_DB_FOLDER)
+		con = sqlite.connect(logger.LOG_DB_FILE)
+		os.chdir(back)
+		cur = con.cursor()
+		try:
+			cur.executescript(
+				'''
+				DROP INDEX IF EXISTS idx_logs_jid_id_kind;
+
+				CREATE INDEX IF NOT EXISTS
+				idx_logs_jid_id_time ON logs (jid_id, time DESC);
+				'''
+			)
+			con.commit()
+		except sqlite.OperationalError:
+			pass
+		con.close()
+		gajim.config.set('version', '0.13.10.1')
+
 # vim: se ts=3:
-- 
GitLab