From 4d64efcda9f0b9c31776dfe01274d10931d4c795 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 10 Apr 2019 21:04:41 +0200 Subject: [PATCH] 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. --- sat/core/xmpp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index e3052c17..eddbe9d5 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -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: