Showing History dialog takes a long time for contacts with long history.
I optimalized the
get_days_with_logs() function a little bit. It took about 5 to 11 seconds and now its 1 or 2 sec. But something else still takes a long time...
Here it is: (I dont speak python. Please check if it really works well ;)
def get_days_with_logs(self, jid, year, month, max_day, account): '''returns the list of days that have logs (not status messages)''' jid = jid.lower() jid_id = self.get_jid_id(jid) days_with_logs =  where_sql = self._build_contact_where(account, jid) # 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 last_second_of_month = start_of_month + (seconds_in_a_day * max_day) - 1 # Select times and 'floor' them to time 0:00 # (by dividing, they are integers) # and take only one of the same values (distinct) # Now we have timestamps of time 0:00 of every day with logs self.cur.execute(''' SELECT distinct time/(86400)*86400 FROM logs WHERE (%s) AND time BETWEEN %d AND %d AND kind NOT IN (%d, %d) ''' % (where_sql, start_of_month, last_second_of_month, constants.KIND_STATUS, constants.KIND_GCSTATUS)) result = self.cur.fetchall() # convert timestamps to day of month for line in result: days_with_logs[0:0]=[time.gmtime(line)] return days_with_logs