From 86fbcece1ffdaeb01729951ecb1aa15fc9682f7f Mon Sep 17 00:00:00 2001 From: Jean-Marie Traissard Date: Tue, 9 Jan 2007 17:30:03 +0000 Subject: [PATCH] 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) --- src/common/connection.py | 16 +++++++++++----- src/common/logger.py | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 62a19fc0c..e3610cc75 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1113,12 +1113,15 @@ class Connection(ConnectionHandlers): if password: t.setTagData('password', password) self.connection.send(p) + #last date/time in history to avoid duplicate - last_log = gajim.logger.get_last_date_that_has_logs(room_jid, - is_room = True) - if last_log is None: - last_log = 0 - self.last_history_line[room_jid]= last_log + if not self.last_history_line.has_key(room_jid): + # Not in memory, get it from DB + last_log = gajim.logger.get_last_date_that_has_logs(room_jid, + is_room = True) + 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): 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 # 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''' diff --git a/src/common/logger.py b/src/common/logger.py index d8f4c7fcd..1e8b53647 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -515,7 +515,7 @@ class Logger: constants.KIND_STATUS, constants.KIND_GCSTATUS)) 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)') for line in result: self.cur.execute(''' @@ -554,10 +554,9 @@ class Logger: jid_id = self.get_jid_id(jid, 'ROOM') where_sql = 'jid_id = %s' % jid_id self.cur.execute(''' - SELECT time FROM logs + SELECT MAX(time) FROM logs WHERE (%s) AND kind NOT IN (%d, %d) - ORDER BY time DESC LIMIT 1 ''' % (where_sql, constants.KIND_STATUS, constants.KIND_GCSTATUS)) results = self.cur.fetchone()