split logs.db into logs.db and cache.db. Fixes #2845
This commit is contained in:
parent
ebf9407c5d
commit
46b50f48a1
|
@ -1,5 +1,5 @@
|
|||
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_CONFIG_HEADER(config.h)
|
||||
|
|
|
@ -63,11 +63,6 @@ def create_log_db():
|
|||
|
||||
CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
|
||||
|
||||
CREATE TABLE transports_cache (
|
||||
transport TEXT UNIQUE,
|
||||
type INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE logs(
|
||||
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
jid_id INTEGER,
|
||||
|
@ -80,6 +75,23 @@ def create_log_db():
|
|||
);
|
||||
|
||||
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 (
|
||||
hash_method TEXT,
|
||||
|
@ -115,6 +127,7 @@ def create_log_db():
|
|||
|
||||
def check_and_possibly_create_paths():
|
||||
LOG_DB_PATH = logger.LOG_DB_PATH
|
||||
CACHE_DB_PATH = logger.CACHE_DB_PATH
|
||||
VCARD_PATH = gajim.VCARD_PATH
|
||||
AVATAR_PATH = gajim.AVATAR_PATH
|
||||
dot_gajim = os.path.dirname(VCARD_PATH)
|
||||
|
@ -149,6 +162,13 @@ def check_and_possibly_create_paths():
|
|||
print _('Gajim will now 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
|
||||
if dot_gajim: # is '' on win9x so avoid that
|
||||
create_path(dot_gajim)
|
||||
|
@ -159,6 +179,9 @@ def check_and_possibly_create_paths():
|
|||
if not os.path.isfile(LOG_DB_PATH):
|
||||
create_log_db()
|
||||
gajim.logger.init_vars()
|
||||
if not os.path.isfile(CACHE_DB_PATH):
|
||||
create_cache_db()
|
||||
gajim.logger.attach_cache_database()
|
||||
|
||||
def create_path(directory):
|
||||
print _('creating %s directory') % directory
|
||||
|
|
|
@ -105,11 +105,11 @@ class ConfigPaths:
|
|||
self.root = root
|
||||
|
||||
# LOG is deprecated
|
||||
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS',
|
||||
'MY_ICONSETS', 'MY_MOOD_ICONSETS',
|
||||
'MY_ACTIVITY_ICONSETS', 'MY_CACERTS')
|
||||
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons',
|
||||
u'iconsets', u'moods', u'activities', u'cacerts.pem')
|
||||
k = ( 'LOG', 'LOG_DB', 'CACHE_DB', 'VCARD', 'AVATAR', 'MY_EMOTS',
|
||||
'MY_ICONSETS', 'MY_MOOD_ICONSETS', 'MY_ACTIVITY_ICONSETS',
|
||||
'MY_CACERTS')
|
||||
v = (u'logs', u'logs.db', u'cache.db', u'vcards', u'avatars',
|
||||
u'emoticons', u'iconsets', u'moods', u'activities', u'cacerts.pem')
|
||||
|
||||
if os.name == 'nt':
|
||||
v = [x.capitalize() for x in v]
|
||||
|
|
|
@ -27,7 +27,7 @@ docdir = '../'
|
|||
basedir = '../'
|
||||
localedir = '../po'
|
||||
|
||||
version = '0.13.10.1-dev'
|
||||
version = '0.13.10.2-dev'
|
||||
|
||||
import sys, os.path
|
||||
for base in ('.', 'common'):
|
||||
|
|
|
@ -43,6 +43,7 @@ import sqlite3 as sqlite
|
|||
import configpaths
|
||||
LOG_DB_PATH = configpaths.gajimpaths['LOG_DB']
|
||||
LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH)
|
||||
CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB']
|
||||
|
||||
class Constants:
|
||||
def __init__(self):
|
||||
|
@ -107,6 +108,11 @@ class Logger:
|
|||
# db is not created here but in src/common/checks_paths.py
|
||||
return
|
||||
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):
|
||||
if self.con:
|
||||
|
@ -132,6 +138,12 @@ class Logger:
|
|||
self.cur = self.con.cursor()
|
||||
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):
|
||||
try:
|
||||
if sync:
|
||||
|
|
|
@ -216,8 +216,11 @@ class OptionsParser:
|
|||
self.update_config_to_013100()
|
||||
if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]:
|
||||
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.attach_cache_database()
|
||||
gajim.config.set('version', new_version)
|
||||
|
||||
caps_cache.capscache.initialize_from_db()
|
||||
|
@ -880,4 +883,24 @@ class OptionsParser:
|
|||
con.close()
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue