split logs.db into logs.db and cache.db. Fixes #2845

This commit is contained in:
Yann Leboulanger 2010-01-29 11:25:06 +01:00
parent ebf9407c5d
commit 46b50f48a1
6 changed files with 70 additions and 12 deletions

View File

@ -1,5 +1,5 @@
AC_INIT([Gajim - A Jabber Instant Messager], AC_INIT([Gajim - A Jabber Instant Messager],
[0.13.10.1-dev],[http://trac.gajim.org/],[gajim]) [0.13.10.2-dev],[http://trac.gajim.org/],[gajim])
AC_PREREQ([2.59]) AC_PREREQ([2.59])
AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(config.h)

View File

@ -63,11 +63,6 @@ def create_log_db():
CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id); CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
CREATE TABLE transports_cache (
transport TEXT UNIQUE,
type INTEGER
);
CREATE TABLE logs( CREATE TABLE logs(
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
jid_id INTEGER, jid_id INTEGER,
@ -80,6 +75,23 @@ def create_log_db():
); );
CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC); CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC);
'''
)
con.commit()
con.close()
def create_cache_db():
print _('creating cache database')
con = sqlite.connect(logger.CACHE_DB_PATH)
os.chmod(logger.CACHE_DB_PATH, 0600) # rw only for us
cur = con.cursor()
cur.executescript(
'''
CREATE TABLE transports_cache (
transport TEXT UNIQUE,
type INTEGER
);
CREATE TABLE caps_cache ( CREATE TABLE caps_cache (
hash_method TEXT, hash_method TEXT,
@ -115,6 +127,7 @@ def create_log_db():
def check_and_possibly_create_paths(): def check_and_possibly_create_paths():
LOG_DB_PATH = logger.LOG_DB_PATH LOG_DB_PATH = logger.LOG_DB_PATH
CACHE_DB_PATH = logger.CACHE_DB_PATH
VCARD_PATH = gajim.VCARD_PATH VCARD_PATH = gajim.VCARD_PATH
AVATAR_PATH = gajim.AVATAR_PATH AVATAR_PATH = gajim.AVATAR_PATH
dot_gajim = os.path.dirname(VCARD_PATH) dot_gajim = os.path.dirname(VCARD_PATH)
@ -149,6 +162,13 @@ def check_and_possibly_create_paths():
print _('Gajim will now exit') print _('Gajim will now exit')
sys.exit() sys.exit()
if not os.path.exists(CACHE_DB_PATH):
create_cache_db()
elif os.path.isdir(CACHE_DB_PATH):
print _('%s is a directory but should be a file') % CACHE_DB_PATH
print _('Gajim will now exit')
sys.exit()
else: # dot_gajim doesn't exist else: # dot_gajim doesn't exist
if dot_gajim: # is '' on win9x so avoid that if dot_gajim: # is '' on win9x so avoid that
create_path(dot_gajim) create_path(dot_gajim)
@ -159,6 +179,9 @@ def check_and_possibly_create_paths():
if not os.path.isfile(LOG_DB_PATH): if not os.path.isfile(LOG_DB_PATH):
create_log_db() create_log_db()
gajim.logger.init_vars() gajim.logger.init_vars()
if not os.path.isfile(CACHE_DB_PATH):
create_cache_db()
gajim.logger.attach_cache_database()
def create_path(directory): def create_path(directory):
print _('creating %s directory') % directory print _('creating %s directory') % directory

View File

@ -105,11 +105,11 @@ class ConfigPaths:
self.root = root self.root = root
# LOG is deprecated # LOG is deprecated
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS', k = ( 'LOG', 'LOG_DB', 'CACHE_DB', 'VCARD', 'AVATAR', 'MY_EMOTS',
'MY_ICONSETS', 'MY_MOOD_ICONSETS', 'MY_ICONSETS', 'MY_MOOD_ICONSETS', 'MY_ACTIVITY_ICONSETS',
'MY_ACTIVITY_ICONSETS', 'MY_CACERTS') 'MY_CACERTS')
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons', v = (u'logs', u'logs.db', u'cache.db', u'vcards', u'avatars',
u'iconsets', u'moods', u'activities', u'cacerts.pem') u'emoticons', u'iconsets', u'moods', u'activities', u'cacerts.pem')
if os.name == 'nt': if os.name == 'nt':
v = [x.capitalize() for x in v] v = [x.capitalize() for x in v]

View File

@ -27,7 +27,7 @@ docdir = '../'
basedir = '../' basedir = '../'
localedir = '../po' localedir = '../po'
version = '0.13.10.1-dev' version = '0.13.10.2-dev'
import sys, os.path import sys, os.path
for base in ('.', 'common'): for base in ('.', 'common'):

View File

@ -43,6 +43,7 @@ import sqlite3 as sqlite
import configpaths import configpaths
LOG_DB_PATH = configpaths.gajimpaths['LOG_DB'] LOG_DB_PATH = configpaths.gajimpaths['LOG_DB']
LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH) LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH)
CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB']
class Constants: class Constants:
def __init__(self): def __init__(self):
@ -107,6 +108,11 @@ class Logger:
# db is not created here but in src/common/checks_paths.py # db is not created here but in src/common/checks_paths.py
return return
self.init_vars() self.init_vars()
if not os.path.exists(CACHE_DB_PATH):
# this can happen cache database is not present when gajim is launched
# db will be created in src/common/checks_paths.py
return
self.attach_cache_database()
def close_db(self): def close_db(self):
if self.con: if self.con:
@ -132,6 +138,12 @@ class Logger:
self.cur = self.con.cursor() self.cur = self.con.cursor()
self.set_synchronous(False) self.set_synchronous(False)
def attach_cache_database(self):
try:
self.cur.execute("ATTACH DATABASE '%s' AS cache" % CACHE_DB_PATH)
except sqlite.Error, e:
gajim.log.debug("Failed to attach cache database: %s" % str(e))
def set_synchronous(self, sync): def set_synchronous(self, sync):
try: try:
if sync: if sync:

View File

@ -216,8 +216,11 @@ class OptionsParser:
self.update_config_to_013100() self.update_config_to_013100()
if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]: if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]:
self.update_config_to_013101() self.update_config_to_013101()
if old < [0, 13, 10, 2] and new >= [0, 13, 10, 2]:
self.update_config_to_013102()
gajim.logger.init_vars() gajim.logger.init_vars()
gajim.logger.attach_cache_database()
gajim.config.set('version', new_version) gajim.config.set('version', new_version)
caps_cache.capscache.initialize_from_db() caps_cache.capscache.initialize_from_db()
@ -880,4 +883,24 @@ class OptionsParser:
con.close() con.close()
gajim.config.set('version', '0.13.10.1') gajim.config.set('version', '0.13.10.1')
def update_config_to_013102(self):
back = os.getcwd()
os.chdir(logger.LOG_DB_FOLDER)
con = sqlite.connect(logger.LOG_DB_FILE)
os.chdir(back)
cur = con.cursor()
cur.execute("ATTACH DATABASE '%s' AS cache" % logger.CACHE_DB_PATH)
for table in ('caps_cache', 'rooms_last_message_time', 'roster_entry',
'roster_group', 'transports_cache'):
try:
cur.executescript(
'INSERT INTO cache.%s SELECT * FROM %s;' % (table, table))
con.commit()
cur.executescript('DROP TABLE %s;' % table)
con.commit()
except sqlite.OperationalError:
print >> sys.stderr, 'error moving table %s to cache.db'
con.close()
gajim.config.set('version', '0.13.10.2')
# vim: se ts=3: # vim: se ts=3: