optimize history search. Fixes #6997

This commit is contained in:
Denis Fomin 2011-12-18 21:28:47 +04:00
parent b502f35a9f
commit 783cf55ba7
3 changed files with 41 additions and 4 deletions

View File

@ -80,6 +80,21 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="search_in_date">
<property name="label" translatable="yes">_In date search</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -104,14 +119,17 @@
<object class="GtkCalendar" id="calendar">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="day_selected" handler="on_calendar_day_selected"/>
<signal name="month_changed" handler="on_calendar_month_changed"/>
<signal name="day_selected" handler="on_calendar_day_selected"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="resize">False</property>

View File

@ -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

View File

@ -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)