From be7f07ad1231b30bf953f0761773af46db952c62 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 5 Mar 2012 11:11:35 -0800 Subject: [PATCH] Prevent excess loading from the roster db. Fixes issue #148 --- sleekxmpp/roster/multi.py | 10 ++++++---- sleekxmpp/roster/single.py | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sleekxmpp/roster/multi.py b/sleekxmpp/roster/multi.py index 28876814..84577a9d 100644 --- a/sleekxmpp/roster/multi.py +++ b/sleekxmpp/roster/multi.py @@ -9,7 +9,6 @@ from sleekxmpp.xmlstream import JID from sleekxmpp.roster import RosterNode - class Roster(object): """ @@ -104,10 +103,13 @@ class Roster(object): db -- The new datastore interface. """ self.db = db - for node in self.db.entries(None, {}): - self.add(node) - for node in self._rosters: + existing_entries = set(self._rosters) + new_entries = set(self.db.entries(None, {})) + + for node in existing_entries: self._rosters[node].set_backend(db) + for node in new_entries - existing_entries: + self.add(node) def reset(self): """ diff --git a/sleekxmpp/roster/single.py b/sleekxmpp/roster/single.py index 633f23f6..611f8944 100644 --- a/sleekxmpp/roster/single.py +++ b/sleekxmpp/roster/single.py @@ -109,10 +109,13 @@ class RosterNode(object): db -- The new datastore interface. """ self.db = db - for jid in self.db.entries(self.jid): - self.add(jid) - for jid in self._jids: + existing_entries = set(self._jids) + new_entries = set(self.db.entries(self.jid, {})) + + for jid in existing_entries: self._jids[jid].set_backend(db) + for jid in new_entries - existing_entries: + self.add(jid) def add(self, jid, name='', groups=None, afrom=False, ato=False, pending_in=False, pending_out=False, whitelisted=False,