[Jim] faster version of do_possible_mark_for_days_in_this_month()

This commit is contained in:
Yann Leboulanger 2005-12-21 10:54:41 +00:00
parent ff98aab6b2
commit ebccabf5da
2 changed files with 44 additions and 22 deletions

View File

@ -343,30 +343,53 @@ class Logger:
results = self.cur.fetchall() results = self.cur.fetchall()
return results return results
def date_has_logs(self, jid, year, month, day): def get_days_with_logs(self, jid, year, month, max_day):
'''returns True if we have logs (excluding statuses) for given date, '''returns the list of days that have logs (not status messages)'''
else False'''
jid = jid.lower() jid = jid.lower()
jid_id = self.get_jid_id(jid) jid_id = self.get_jid_id(jid)
list = []
start_of_day = self.get_unix_time_from_date(year, month, day) # First select all date of month whith logs we want
start_of_month = self.get_unix_time_from_date(year, month, 1)
seconds_in_a_day = 86400 # 60 * 60 * 24 seconds_in_a_day = 86400 # 60 * 60 * 24
last_second_of_day = start_of_day + seconds_in_a_day - 1 last_second_of_month = start_of_month + (seconds_in_a_day * max_day) - 1
# just ask one row to see if we have sth for this date
self.cur.execute(''' self.cur.execute('''
SELECT kind FROM logs SELECT time FROM logs
WHERE jid_id = %d WHERE jid_id = %d
AND time BETWEEN %d AND %d AND time BETWEEN %d AND %d
AND kind NOT IN (%d, %d) AND kind NOT IN (%d, %d)
LIMIT 1 ORDER BY time
''' % (jid_id, start_of_day, last_second_of_day, ''' % (jid_id, start_of_month, last_second_of_month,
constants.KIND_STATUS, constants.KIND_GCSTATUS)) constants.KIND_STATUS, constants.KIND_GCSTATUS))
result = self.cur.fetchall()
#Copy all interesant time in a temporary table
self.cur.execute('CREATE TEMPORARY TABLE blabla(time,INTEGER)')
for line in result:
self.cur.execute('''
INSERT INTO blabla (time) VALUES (%d)
''' % (line[0]))
#then search in this small temp table for each day
for day in xrange(1, max_day):
start_of_day = self.get_unix_time_from_date(year, month, day)
last_second_of_day = start_of_day + seconds_in_a_day - 1
# just ask one row to see if we have sth for this date
self.cur.execute('''
SELECT time FROM blabla
WHERE time BETWEEN %d AND %d
LIMIT 1
''' % (start_of_day, last_second_of_day))
result = self.cur.fetchone()
if result:
list[0:0]=[day]
#Delete temporary table
self.cur.execute('DROP TABLE blabla')
result = self.cur.fetchone() result = self.cur.fetchone()
if result: return list
return True
else:
return False
def get_last_date_that_has_logs(self, jid): def get_last_date_that_has_logs(self, jid):
'''returns last time (in seconds since EPOCH) for which '''returns last time (in seconds since EPOCH) for which

View File

@ -156,13 +156,12 @@ class HistoryWindow:
so it runs progressively! yea :) so it runs progressively! yea :)
asks for days in this month if they have logs it bolds them (marks them)''' asks for days in this month if they have logs it bolds them (marks them)'''
weekday, days_in_this_month = calendar.monthrange(year, month) weekday, days_in_this_month = calendar.monthrange(year, month)
# count from 1 (gtk counts from 1), so add 1 more log_days = gajim.logger.get_days_with_logs(self.jid, year,
for day in xrange(1, days_in_this_month + 1): month, days_in_this_month)
#print 'ask for logs for date:', year, month, day for day in log_days:
if gajim.logger.date_has_logs(self.jid, year, month, day): widget.mark_day(day)
widget.mark_day(day) yield True
yield True # we have more work to do yield False
yield False # we're done with this work
def on_calendar_month_changed(self, widget): def on_calendar_month_changed(self, widget):
year, month, day = widget.get_date() # integers year, month, day = widget.get_date() # integers