From af9f4afe0c4d1f7c3d39184aa7af69387edc5a51 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sun, 27 Nov 2005 17:33:57 +0000 Subject: [PATCH] ask sql to do the timeout check --- src/common/logger.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 6b85e8238..b036ac0e8 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -272,26 +272,22 @@ class Logger: list with empty tupple if nothing found to meet our demands''' jid = jid.lower() jid_id = self.get_jid_id(jid) + now = int(float(time.time())) + timed_out = now - (timeout * 60) # before that they are too old # so if we ask last 5 lines and we have 2 pending we get # 3 - 8 (we avoid the last 2 lines but we still return 5 asked) cur.execute(''' SELECT time, kind, message FROM logs - WHERE jid_id = %d AND kind IN (%d, %d, %d, %d) + WHERE jid_id = %d AND kind IN (%d, %d, %d, %d) AND time > %d ORDER BY time DESC LIMIT %d OFFSET %d ''' % (jid_id, constants.KIND_SINGLE_MSG_RECV, constants.KIND_CHAT_MSG_RECV, constants.KIND_SINGLE_MSG_SENT, constants.KIND_CHAT_MSG_SENT, - restore_how_many_rows, pending_how_many) + timed_out, restore_how_many_rows, pending_how_many) ) results = cur.fetchall() - now = time.time() - true_results = [] # results that are not too old - for result in results: - if result[0] < (now - timeout*60): # fom here they are too old - break - true_results.append(result) - true_results.reverse() - return true_results + results.reverse() + return results def get_unix_time_from_date(self, year, month, day): # year (fe 2005), month (fe 11), day (fe 25)