use the GOOD syntax for the get_last_date_that_has_logs() SQL request :)

(Open gc win three times faster, and even more when time cached !
Also opens history wins two times faster)
This commit is contained in:
Jean-Marie Traissard 2007-01-09 17:30:03 +00:00
parent a57d59edaf
commit 86fbcece1f
2 changed files with 13 additions and 8 deletions

View file

@ -1113,12 +1113,15 @@ class Connection(ConnectionHandlers):
if password: if password:
t.setTagData('password', password) t.setTagData('password', password)
self.connection.send(p) self.connection.send(p)
#last date/time in history to avoid duplicate #last date/time in history to avoid duplicate
last_log = gajim.logger.get_last_date_that_has_logs(room_jid, if not self.last_history_line.has_key(room_jid):
is_room = True) # Not in memory, get it from DB
if last_log is None: last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
last_log = 0 is_room = True)
self.last_history_line[room_jid]= last_log if last_log is None:
last_log = 0
self.last_history_line[room_jid]= last_log
def send_gc_message(self, jid, msg, xhtml = None): def send_gc_message(self, jid, msg, xhtml = None):
if not self.connection: if not self.connection:
@ -1163,6 +1166,9 @@ class Connection(ConnectionHandlers):
# send instantly so when we go offline, status is sent to gc before we # send instantly so when we go offline, status is sent to gc before we
# disconnect from jabber server # disconnect from jabber server
self.connection.send(p) 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 = ''): 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''' '''role is for all the life of the room so it's based on nick'''

View file

@ -515,7 +515,7 @@ class Logger:
constants.KIND_STATUS, constants.KIND_GCSTATUS)) constants.KIND_STATUS, constants.KIND_GCSTATUS))
result = self.cur.fetchall() result = self.cur.fetchall()
# Copy all interesant time in a temporary table # Copy all interesting times in a temporary table
self.cur.execute('CREATE TEMPORARY TABLE blabla(time,INTEGER)') self.cur.execute('CREATE TEMPORARY TABLE blabla(time,INTEGER)')
for line in result: for line in result:
self.cur.execute(''' self.cur.execute('''
@ -554,10 +554,9 @@ class Logger:
jid_id = self.get_jid_id(jid, 'ROOM') jid_id = self.get_jid_id(jid, 'ROOM')
where_sql = 'jid_id = %s' % jid_id where_sql = 'jid_id = %s' % jid_id
self.cur.execute(''' self.cur.execute('''
SELECT time FROM logs SELECT MAX(time) FROM logs
WHERE (%s) WHERE (%s)
AND kind NOT IN (%d, %d) AND kind NOT IN (%d, %d)
ORDER BY time DESC LIMIT 1
''' % (where_sql, constants.KIND_STATUS, constants.KIND_GCSTATUS)) ''' % (where_sql, constants.KIND_STATUS, constants.KIND_GCSTATUS))
results = self.cur.fetchone() results = self.cur.fetchone()