Create a new small table in DB to remember rooms last_history_line at next

launch. This is necessary because with a big history get_last_date_that_has_logs
can take about 5 seconds on first launch.
Created new gajim subversion.
This commit is contained in:
Jean-Marie Traissard 2008-04-15 01:52:11 +00:00
parent 29dd9d2576
commit f32901d243
6 changed files with 80 additions and 14 deletions

View file

@ -1,5 +1,5 @@
AC_INIT([Gajim - A Jabber Instant Messager],
[0.11.4.2-svn],[http://trac.gajim.org/],[gajim])
[0.11.4.3-svn],[http://trac.gajim.org/],[gajim])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.8])
AC_CONFIG_HEADER(config.h)

View file

@ -86,6 +86,10 @@ def create_log_db():
ver TEXT,
ext TEXT,
data BLOB);
CREATE TABLE IF NOT EXISTS rooms_last_message_time(
jid_id INTEGER PRIMARY KEY UNIQUE,
time INTEGER
'''
)

View file

@ -1443,13 +1443,19 @@ class Connection(ConnectionHandlers):
# last date/time in history to avoid duplicate
if not self.last_history_line.has_key(room_jid):
# Not in memory, get it from DB
last_log = None
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
.split()
if self.name not in no_log_for and room_jid not in no_log_for:
last_log = None
# Do not check if we are not logging for this room
last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
is_room = True)
if self.name not in no_log_for and room_jid not in no_log_for:
# Check time first in the FAST table
last_log = gajim.logger.get_room_last_message_time(room_jid)
if last_log is None:
# Not in special table, get it from messages DB
last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
is_room = True)
# Create self.last_history_line[room_jid] even if not logging,
# could be used in connection_handlers
if last_log is None:
last_log = 0
self.last_history_line[room_jid]= last_log
@ -1497,6 +1503,12 @@ class Connection(ConnectionHandlers):
ptype = None
if show == 'offline':
ptype = 'unavailable'
# Save the time we quit to avoid duplicate logs AND be faster than
# get that date from DB. Save it in mem AND in a small table (with
# fast access)
log_time = time_time()
self.last_history_line[jid] = log_time
gajim.logger.set_room_last_message_time(jid, log_time)
xmpp_show = helpers.get_xmpp_show(show)
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
show = xmpp_show, status = status)
@ -1506,9 +1518,6 @@ class Connection(ConnectionHandlers):
# send instantly so when we go offline, status is sent to gc before we
# disconnect from jabber server
self.connection.send(p)
# Save the time we quit to avoid duplicate logs AND be faster than
# get that date from DB
self.last_history_line[jid] = time_time()
def gc_set_role(self, room_jid, nick, role, reason = ''):
'''role is for all the life of the room so it's based on nick'''

View file

@ -2,7 +2,7 @@ docdir = '../'
datadir = '../'
version = '0.11.4.2-svn'
version = '0.11.4.3-svn'
import sys, os.path
for base in ('.', 'common'):

View file

@ -553,10 +553,10 @@ class Logger:
result = self.cur.fetchall()
# Copy all interesting times in a temporary table
self.cur.execute('CREATE TEMPORARY TABLE blabla(time,INTEGER)')
self.cur.execute('CREATE TEMPORARY TABLE temp_table(time,INTEGER)')
for line in result:
self.cur.execute('''
INSERT INTO blabla (time) VALUES (%d)
INSERT INTO temp_table (time) VALUES (%d)
''' % (line[0]))
# then search in this small temp table for each day
@ -566,7 +566,7 @@ class Logger:
# just ask one row to see if we have sth for this date
self.cur.execute('''
SELECT time FROM blabla
SELECT time FROM temp_table
WHERE time BETWEEN %d AND %d
LIMIT 1
''' % (start_of_day, last_second_of_day))
@ -575,7 +575,7 @@ class Logger:
days_with_logs[0:0]=[day]
# Delete temporary table
self.cur.execute('DROP TABLE blabla')
self.cur.execute('DROP TABLE temp_table')
result = self.cur.fetchone()
return days_with_logs
@ -599,9 +599,38 @@ class Logger:
result = results[0]
else:
result = None
return result
def get_room_last_message_time(self, jid):
'''returns FASTLY last time (in seconds since EPOCH) for which
we had logs for that room from rooms_last_message_time table'''
jid_id = self.get_jid_id(jid, 'ROOM')
where_sql = 'jid_id = %s' % jid_id
self.cur.execute('''
SELECT time FROM rooms_last_message_time
WHERE (%s)
''' % (where_sql))
results = self.cur.fetchone()
if results is not None:
result = results[0]
else:
result = None
return result
def set_room_last_message_time(self, jid, time):
'''set last time (in seconds since EPOCH) for which
we had logs for that room in rooms_last_message_time table'''
jid_id = self.get_jid_id(jid, 'ROOM')
# jid_id is unique in this table, create or update :
sql = 'REPLACE INTO rooms_last_message_time VALUES (%d, %d)' % \
(jid_id, time)
self.cur.execute(sql)
try:
self.con.commit()
except sqlite.OperationalError, e:
print >> sys.stderr, str(e)
def _build_contact_where(self, account, jid):
'''build the where clause for a jid, including metacontacts
jid(s) if any'''

View file

@ -178,6 +178,8 @@ class OptionsParser:
self.update_config_to_01141()
if old < [0, 11, 4, 2] and new >= [0, 11, 4, 2]:
self.update_config_to_01142()
if old < [0, 11, 4, 3] and new >= [0, 11, 4, 3]:
self.update_config_to_01143()
gajim.logger.init_vars()
gajim.config.set('version', new_version)
@ -543,3 +545,25 @@ class OptionsParser:
gajim.config.set_per('soundevents', 'next_message_received_focused',
'path', path)
gajim.config.set('version', '0.11.1.2')
def update_config_to_01143(self):
print "updating"
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(
'''
CREATE TABLE IF NOT EXISTS rooms_last_message_time(
jid_id INTEGER PRIMARY KEY UNIQUE,
time INTEGER
);
'''
)
con.commit()
except sqlite.OperationalError, e:
pass
con.close()
gajim.config.set('version', '0.11.4.3')