From 4e441258b3a135a3439e10a5ecbbbac6d299581d Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 13 May 2022 18:43:42 +0200 Subject: [PATCH] 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 --- sat/plugins/plugin_pubsub_cache.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sat/plugins/plugin_pubsub_cache.py b/sat/plugins/plugin_pubsub_cache.py index 2d0b541d..d55f376d 100644 --- a/sat/plugins/plugin_pubsub_cache.py +++ b/sat/plugins/plugin_pubsub_cache.py @@ -277,6 +277,19 @@ class PubsubCache: 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 @@ class PubsubCache: 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" )