From d00a5f737c9e6eae6749015dc87cf68da2b6bd88 Mon Sep 17 00:00:00 2001 From: Stephan Erb 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 122ab5528..57fcdf7b8 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 bdedcca9a..11a8d23a6 100644 --- a/src/common/defs.py +++ b/src/common/defs.py @@ -27,7 +27,7 @@ docdir = '../' 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 573d9ed07..7b7fe911d 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -214,6 +214,8 @@ class OptionsParser: 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 @@ class OptionsParser: 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: