# HG changeset patch # User Goffi # Date 1652460222 -7200 # Node ID c4881833cf8ab6a58edb29c5c5c4dbb6a7d42357 # Parent b7cef1b24f8323e23868ce07c212a19b2407f45a plugin pubsub cache: more resilient node caching: - cache only latest 20 items when disco infos are hidden and thus we can't discover feature/RSM implementation - better handling of args when calling `storage.getItems` rel 365 diff -r b7cef1b24f83 -r c4881833cf8a sat/plugins/plugin_pubsub_cache.py --- a/sat/plugins/plugin_pubsub_cache.py Fri May 13 18:38:05 2022 +0200 +++ b/sat/plugins/plugin_pubsub_cache.py Fri May 13 18:43:42 2022 +0200 @@ -277,6 +277,19 @@ await self.host.checkFeatures( client, [rsm.NS_RSM, self._p.DISCO_RSM], pubsub_node.service ) + except error.StanzaError as e: + if e.condition == "service-unavailable": + log.warning( + "service is hidding disco infos, we'll only cache latest 20 items" + ) + items, __ = await client.pubsub_client.items( + pubsub_node.service, pubsub_node.name, maxItems=20 + ) + await self.cacheItems( + client, pubsub_node, items + ) + else: + raise e except exceptions.FeatureNotFound: log.warning( f"service {service} doesn't handle Result Set Management " @@ -493,12 +506,16 @@ raise NotImplementedError("MAM queries are not supported yet") if max_items is None and rsm_request is None: max_items = 20 - if max_items is not None: + pubsub_items, metadata = await self.host.memory.storage.getItems( + node, max_items=max_items, item_ids=item_ids, + order_by=extra.get(C.KEY_ORDER_BY) + ) + elif max_items is not None: if rsm_request is not None: raise exceptions.InternalError( "Pubsub max items and RSM must not be used at the same time" ) - elif item_ids is None: + elif item_ids: raise exceptions.InternalError( "Pubsub max items and item IDs must not be used at the same time" )