Philipp Hörist pushed to branch master at gajim / gajim
Commits:
1405f22f by lovetox at 2022-07-10T17:00:19+02:00
perf: Roster: Sort more efficiently
- - - - -
2 changed files:
- gajim/common/modules/contacts.py
- gajim/gtk/roster.py
Changes:
=====================================
gajim/common/modules/contacts.py
=====================================
@@ -144,6 +144,16 @@ def get_contact(self,
contact = contact.get_resource(resource)
return contact
+ def get_bare_contact(self, jid: Union[str, JID]) -> Union[BareContact,
+
GroupchatContact]:
+ '''This method gives direct access to the contacts dict.
+ This is helpful when performance is essential. In difference to
+ get_contact() this method does not create contacts nor can it handle
+ JIDs which are not bare. Use this only if you know the contact
+ exists.
+ '''
+ return self._contacts[jid]
+
def get_group_chat_contact(self,
jid: Union[str, JID]
) -> Union[BareContact,
=====================================
gajim/gtk/roster.py
=====================================
@@ -79,6 +79,7 @@ def __init__(self, account: str) -> None:
self._account = account
self._client = app.get_client(account)
+ self._contacts = self._client.get_module('Contacts')
self._roster_tooltip = RosterTooltip()
@@ -195,9 +196,6 @@ def _remove_actions(self):
for action in actions:
app.window.remove_action(f'{action}-{self._account}')
- def _get_contact(self, jid: str) -> types.BareContact:
- return self._client.get_module('Contacts').get_contact(jid)
-
def _on_account_state(self, _event: ApplicationEvent) -> None:
self.update_actions()
@@ -300,7 +298,8 @@ def _on_query_tooltip(self,
self._roster_tooltip.clear_tooltip()
return False
- contact = self._get_contact(model[iter_][Column.JID_OR_GROUP])
+ contact = self._contacts.get_bare_contact(
+ model[iter_][Column.JID_OR_GROUP])
value, widget = self._roster_tooltip.get_tooltip(path, contact)
tooltip.set_custom(widget)
return value
@@ -352,7 +351,7 @@ def _on_remove_contact(self,
param: GLib.Variant):
jid = JID.from_string(param.get_string())
- selected_contact = self._client.get_module('Contacts').get_contact(jid)
+ selected_contact = self._contacts.get_contact(jid)
if selected_contact.is_gateway:
# Check for transport users in roster and warn about removing the
# transport if there are any
@@ -438,7 +437,7 @@ def _show_contact_menu(self,
treeview: Gtk.TreeView,
event: Gdk.EventButton) -> None:
- contact = self._client.get_module('Contacts').get_contact(jid)
+ contact = self._contacts.get_bare_contact(jid)
gateway_register = contact.is_gateway and contact.supports(
Namespace.REGISTER)
menu = get_roster_menu(
@@ -537,7 +536,7 @@ def _on_roster_received(self, _event: RosterReceived) ->
None:
@event_filter(['account'])
def _on_roster_push(self, event: RosterPush) -> None:
- contact = self._get_contact(str(event.item.jid))
+ contact = self._contacts.get_contact(str(event.item.jid))
if event.item.subscription == 'remove':
contact.disconnect(self)
@@ -665,7 +664,8 @@ def _refilter(self) -> None:
for group in self._store:
group_is_visible = False
for child in group.iterchildren():
- contact = self._get_contact(child[Column.JID_OR_GROUP])
+ contact = self._contacts.get_bare_contact(
+ child[Column.JID_OR_GROUP])
is_visible = self._get_contact_visible(contact)
child[Column.VISIBLE] = is_visible
if is_visible:
@@ -758,8 +758,10 @@ def _tree_compare_iters(self,
if not app.settings.get('sort_by_show_in_roster'):
return locale.strcoll(name1.lower(), name2.lower())
- contact1 = self._get_contact(model[iter1][Column.JID_OR_GROUP])
- contact2 = self._get_contact(model[iter2][Column.JID_OR_GROUP])
+ contact1 = self._contacts.get_bare_contact(
+ model[iter1][Column.JID_OR_GROUP])
+ contact2 = self._contacts.get_bare_contact(
+ model[iter2][Column.JID_OR_GROUP])
if contact1.show != contact2.show:
if contact1.show == PresenceShow.DND:
@@ -795,4 +797,5 @@ def _on_destroy(self, _roster: Roster) -> None:
del self._roster
del self._store
del self._roster_tooltip
+ del self._contacts
app.check_finalize(self)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/1405f22f8215c98dd1b0be50fe6fd85492fabbb6
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/1405f22f8215c98dd1b0be50fe6fd85492fabbb6
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits