comparison sat/core/xmpp.py @ 2901:f6b0088ce247

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.
author Goffi <goffi@goffi.org>
date Wed, 10 Apr 2019 21:04:41 +0200
parents c7c52c0dc13a
children d1fcb8e9aced
comparison
equal deleted inserted replaced
2900:93dfbeb41da8 2901:f6b0088ce247
1265 entity = item.entity 1265 entity = item.entity
1266 log.info(_(u"adding {entity} to roster").format(entity=entity.full())) 1266 log.info(_(u"adding {entity} to roster").format(entity=entity.full()))
1267 if request.version is not None: 1267 if request.version is not None:
1268 # we update the cache in storage 1268 # we update the cache in storage
1269 roster_cache = self.roster_cache 1269 roster_cache = self.roster_cache
1270 roster_cache[entity.full()] = item.toElement().toXml()
1270 roster_cache[ROSTER_VER_KEY] = request.version 1271 roster_cache[ROSTER_VER_KEY] = request.version
1271 roster_cache[entity.full()] = item.toElement().toXml()
1272 1272
1273 try: # update the cache for the groups the contact has been removed from 1273 try: # update the cache for the groups the contact has been removed from
1274 left_groups = set(self._jids[entity].groups).difference(item.groups) 1274 left_groups = set(self._jids[entity].groups).difference(item.groups)
1275 for group in left_groups: 1275 for group in left_groups:
1276 jids_set = self._groups[group] 1276 jids_set = self._groups[group]
1289 entity = request.item.entity 1289 entity = request.item.entity
1290 log.info(_(u"removing {entity} from roster").format(entity=entity.full())) 1290 log.info(_(u"removing {entity} from roster").format(entity=entity.full()))
1291 if request.version is not None: 1291 if request.version is not None:
1292 # we update the cache in storage 1292 # we update the cache in storage
1293 roster_cache = self.roster_cache 1293 roster_cache = self.roster_cache
1294 try:
1295 del roster_cache[request.item.entity.full()]
1296 except KeyError:
1297 # because we don't use load(), cache won't have the key, but it
1298 # will be deleted from storage anyway
1299 pass
1294 roster_cache[ROSTER_VER_KEY] = request.version 1300 roster_cache[ROSTER_VER_KEY] = request.version
1295 del roster_cache[request.item.entity.full()]
1296 1301
1297 # we first remove item from local cache (self._groups and self._jids) 1302 # we first remove item from local cache (self._groups and self._jids)
1298 try: 1303 try:
1299 item = self._jids.pop(entity) 1304 item = self._jids.pop(entity)
1300 except KeyError: 1305 except KeyError: