Prevent excess loading from the roster db.

Fixes issue #148
This commit is contained in:
Lance Stout 2012-03-05 11:11:35 -08:00
parent 830db11b41
commit be7f07ad12
2 changed files with 12 additions and 7 deletions

View file

@ -9,7 +9,6 @@
from sleekxmpp.xmlstream import JID from sleekxmpp.xmlstream import JID
from sleekxmpp.roster import RosterNode from sleekxmpp.roster import RosterNode
class Roster(object): class Roster(object):
""" """
@ -104,10 +103,13 @@ class Roster(object):
db -- The new datastore interface. db -- The new datastore interface.
""" """
self.db = db self.db = db
for node in self.db.entries(None, {}): existing_entries = set(self._rosters)
self.add(node) new_entries = set(self.db.entries(None, {}))
for node in self._rosters:
for node in existing_entries:
self._rosters[node].set_backend(db) self._rosters[node].set_backend(db)
for node in new_entries - existing_entries:
self.add(node)
def reset(self): def reset(self):
""" """

View file

@ -109,10 +109,13 @@ class RosterNode(object):
db -- The new datastore interface. db -- The new datastore interface.
""" """
self.db = db self.db = db
for jid in self.db.entries(self.jid): existing_entries = set(self._jids)
self.add(jid) new_entries = set(self.db.entries(self.jid, {}))
for jid in self._jids:
for jid in existing_entries:
self._jids[jid].set_backend(db) 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, def add(self, jid, name='', groups=None, afrom=False, ato=False,
pending_in=False, pending_out=False, whitelisted=False, pending_in=False, pending_out=False, whitelisted=False,