Use idle_add for history_win._fill_completion_dict (LOT faster)

This commit is contained in:
Jean-Marie Traissard 2008-05-31 19:41:42 +00:00
parent 75cc8f460a
commit 57a1c4b130
1 changed files with 25 additions and 9 deletions

View File

@ -117,22 +117,25 @@ class HistoryWindow:
self.completion_dict = {} self.completion_dict = {}
self.accounts_seen_online = [] # Update dict when new accounts connect self.accounts_seen_online = [] # Update dict when new accounts connect
self.jids_to_search = [] self.jids_to_search = []
self._fill_completion_dict()
# This will load history too
gobject.idle_add(self._fill_completion_dict().next)
if jid: if jid:
self.jid_entry.set_text(jid) self.jid_entry.set_text(jid)
xml.signal_autoconnect(self) xml.signal_autoconnect(self)
self._load_history(jid, account)
self.window.show_all() self.window.show_all()
def _fill_completion_dict(self): def _fill_completion_dict(self):
'''Fill completion_dict for key auto completion. '''Fill completion_dict for key auto completion. Then load history for
current jid (by calling another function).
Key will be either jid or full_completion_name Key will be either jid or full_completion_name
(contact name or long description like "pm-contact from groupchat....") (contact name or long description like "pm-contact from groupchat....")
{key : (jid, account, nick_name, full_completion_name} {key : (jid, account, nick_name, full_completion_name}
this is a generator and does pseudo-threading via idle_add()
''' '''
liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)
@ -151,7 +154,12 @@ class HistoryWindow:
contact_img = gajim.interface.jabber_state_images['16']['online'] contact_img = gajim.interface.jabber_state_images['16']['online']
muc_active_pix = muc_active_img.get_pixbuf() muc_active_pix = muc_active_img.get_pixbuf()
contact_pix = contact_img.get_pixbuf() contact_pix = contact_img.get_pixbuf()
keys = self.completion_dict.keys() keys = self.completion_dict.keys()
# Move the actual jid at first so we load history faster
actual_jid = self.jid_entry.get_text().decode('utf-8')
keys.remove(actual_jid)
keys.insert(0, actual_jid)
# Map jid to info tuple # Map jid to info tuple
# Warning : This for is time critical with big DB # Warning : This for is time critical with big DB
for key in keys: for key in keys:
@ -186,7 +194,11 @@ class HistoryWindow:
info_completion) info_completion)
self.completion_dict[completed] = (info_jid, info_acc, self.completion_dict[completed] = (info_jid, info_acc,
info_name, info_completion) info_name, info_completion)
if key == actual_jid:
self._load_history(info_jid, info_acc)
yield True
keys.sort() keys.sort()
yield False
def _get_account_for_jid(self, jid): def _get_account_for_jid(self, jid):
'''Return the corresponding account of the jid. '''Return the corresponding account of the jid.
@ -480,7 +492,8 @@ class HistoryWindow:
message = row[4] message = row[4]
local_time = time.localtime(tim) local_time = time.localtime(tim)
date = time.strftime('%x', local_time) date = time.strftime('%x', local_time)
# jid (to which log is assigned to), name, date, message, time (full unix time) # jid (to which log is assigned to), name, date, message,
# time (full unix time)
model.append((jid, contact_name, date, message, tim)) model.append((jid, contact_name, date, message, tim))
def on_query_combobox_changed(self, widget): def on_query_combobox_changed(self, widget):
@ -573,9 +586,12 @@ class HistoryWindow:
def open_history(self, jid, account): def open_history(self, jid, account):
'''Load chat history of the specified jid''' '''Load chat history of the specified jid'''
self.jid_entry.set_text(jid)
if account and account not in self.accounts_seen_online: if account and account not in self.accounts_seen_online:
# Update dict to not only show bare jid # Update dict to not only show bare jid
self._fill_completion_dict gobject.idle_add(self._fill_completion_dict().next)
self.jid_entry.set_text(jid) else:
# Only in that case because it's called by self._fill_completion_dict()
# otherwise
self._load_history(jid, account) self._load_history(jid, account)
self.results_window.set_property('visible', False) self.results_window.set_property('visible', False)