From 783cf55ba709a527c2eba07462cce2cfa31816c4 Mon Sep 17 00:00:00 2001 From: Denis Fomin Date: Sun, 18 Dec 2011 21:28:47 +0400 Subject: [PATCH] optimize history search. Fixes #6997 --- data/gui/history_window.ui | 20 +++++++++++++++++++- src/common/logger.py | 17 +++++++++++++++-- src/history_window.py | 8 +++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/data/gui/history_window.ui b/data/gui/history_window.ui index d6b77b799..515c426d8 100644 --- a/data/gui/history_window.ui +++ b/data/gui/history_window.ui @@ -80,6 +80,21 @@ 2 + + + _In date search + True + False + False + True + True + + + False + False + 3 + + False @@ -104,14 +119,17 @@ True True - + False 0 + + + False diff --git a/src/common/logger.py b/src/common/logger.py index ce2f69f6e..ee7e647f1 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -629,7 +629,8 @@ class Logger: results = self.cur.fetchall() return results - def get_search_results_for_query(self, jid, query, account): + def get_search_results_for_query(self, jid, query, account, year=False, + month=False, day=False): """ Returns contact_name, time, kind, show, message @@ -652,7 +653,19 @@ class Logger: else: # user just typed something, we search in message column where_sql, jid_tuple = self._build_contact_where(account, jid) like_sql = '%' + query.replace("'", "''") + '%' - self.cur.execute(''' + if year: + start_of_day = self.get_unix_time_from_date(year, month, day) + seconds_in_a_day = 86400 # 60 * 60 * 24 + last_second_of_day = start_of_day + seconds_in_a_day - 1 + self.cur.execute(''' + SELECT contact_name, time, kind, show, message, subject FROM logs + WHERE (%s) AND message LIKE '%s' + AND time BETWEEN %d AND %d + ORDER BY time + ''' % (where_sql, like_sql, start_of_day, last_second_of_day), + jid_tuple) + else: + self.cur.execute(''' SELECT contact_name, time, kind, show, message, subject FROM logs WHERE (%s) AND message LIKE '%s' ORDER BY time diff --git a/src/history_window.py b/src/history_window.py index 2b03acd1e..958cae331 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -83,6 +83,7 @@ class HistoryWindow: self.query_combobox.set_active(0) self.results_treeview = xml.get_object('results_treeview') self.results_window = xml.get_object('results_scrolledwindow') + self.search_in_date = xml.get_object('search_in_date') # contact_name, date, message, time model = gtk.ListStore(str, str, str, str, str) @@ -511,9 +512,14 @@ class HistoryWindow: # This may leed to wrong self nick in the displayed history (Uggh!) account = gajim.contacts.get_accounts()[0] + year, month, day = False, False, False + if self.search_in_date.get_active(): + year, month, day = self.calendar.get_date() # integers + month = gtkgui_helpers.make_gtk_month_python_month(month) + # contact_name, time, kind, show, message, subject results = gajim.logger.get_search_results_for_query( - jid, text, account) + jid, text, account, year, month, day) #FIXME: # add "subject: | message: " in message column if kind is single # also do we need show at all? (we do not search on subject)