From 498bcb6ccd5dbb042527b57ac83ce8674856874d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 24 Sep 2012 12:24:10 +0200 Subject: [PATCH] decrease call to get_contact(s) function to improve speed. see #7125 --- src/common/contacts.py | 2 +- src/roster_window.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/common/contacts.py b/src/common/contacts.py index cd10d6fa0..88c073242 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -365,7 +365,7 @@ class LegacyContactsAPI: self.is_big_brother(account, jid, accounts): # count metacontacts only once continue - contact = self.get_contact_with_highest_priority(account, jid) + contact = self._accounts[account].contacts._contacts[jid][0] if _('Not in roster') in contact.groups: continue in_groups = False diff --git a/src/roster_window.py b/src/roster_window.py index 0d1f78137..f4a0a2d6c 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1136,16 +1136,18 @@ class RosterWindow: self.draw_contact(parent_jid, parent_account) return False - def draw_contact(self, jid, account, selected=False, focus=False): + def draw_contact(self, jid, account, selected=False, focus=False, contact_instances=None, contact=None): """ Draw the correct state image, name BUT not avatar """ # focus is about if the roster window has toplevel-focus or not # FIXME: We really need a custom cell_renderer - contact_instances = gajim.contacts.get_contacts(account, jid) - contact = gajim.contacts.get_highest_prio_contact_from_contacts( - contact_instances) + if not contact_instances: + contact_instances = gajim.contacts.get_contacts(account, jid) + if not contact: + contact = gajim.contacts.get_highest_prio_contact_from_contacts( + contact_instances) if not contact: return False @@ -1308,11 +1310,11 @@ class RosterWindow: else: return False - def draw_all_pep_types(self, jid, account): + def draw_all_pep_types(self, jid, account, contact=None): for pep_type in self._pep_type_to_model_column: - self.draw_pep(jid, account, pep_type) + self.draw_pep(jid, account, pep_type, contact=contact) - def draw_pep(self, jid, account, pep_type): + def draw_pep(self, jid, account, pep_type, contact=None): if pep_type not in self._pep_type_to_model_column: return if not self._is_pep_shown_in_roster(pep_type): @@ -1322,7 +1324,8 @@ class RosterWindow: iters = self._get_contact_iter(jid, account, model=self.model) if not iters: return - contact = gajim.contacts.get_contact(account, jid) + if not contact: + contact = gajim.contacts.get_contact(account, jid) if pep_type in contact.pep: pixbuf = contact.pep[pep_type].asPixbufIcon() else: @@ -1345,8 +1348,12 @@ class RosterWindow: return False def draw_completely(self, jid, account): - self.draw_contact(jid, account) - self.draw_all_pep_types(jid, account) + contact_instances = gajim.contacts.get_contacts(account, jid) + contact = gajim.contacts.get_highest_prio_contact_from_contacts( + contact_instances) + self.draw_contact(jid, account, contact_instances=contact_instances, + contact=contact) + self.draw_all_pep_types(jid, account, contact=contact) self.draw_avatar(jid, account) def adjust_and_draw_contact_context(self, jid, account):