code (xmpp): store version after roster item update + fix item removal:

roster version is now stored after roster item has been added or removed. This way if something interrupting the process happens, former item update will be received and roster should be updated correctly.

Roster item removal was crashing because `load()` is not used (local PersistentDict cache is then not updated, and the key to remove is missing there). The exception is now catched and ignored to avoid loading the data only to remove an item.
This commit is contained in:
Goffi 2019-04-10 21:04:41 +02:00
commit 4d64efcda9

View file

@ -1267,8 +1267,8 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
if request.version is not None:
# we update the cache in storage
roster_cache = self.roster_cache
roster_cache[ROSTER_VER_KEY] = request.version
roster_cache[entity.full()] = item.toElement().toXml()
roster_cache[ROSTER_VER_KEY] = request.version
try: # update the cache for the groups the contact has been removed from
left_groups = set(self._jids[entity].groups).difference(item.groups)
@ -1291,8 +1291,13 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
if request.version is not None:
# we update the cache in storage
roster_cache = self.roster_cache
try:
del roster_cache[request.item.entity.full()]
except KeyError:
# because we don't use load(), cache won't have the key, but it
# will be deleted from storage anyway
pass
roster_cache[ROSTER_VER_KEY] = request.version
del roster_cache[request.item.entity.full()]
# we first remove item from local cache (self._groups and self._jids)
try: