changeset 3759:c4881833cf8a

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
author Goffi <goffi@goffi.org>
date Fri, 13 May 2022 18:43:42 +0200
parents b7cef1b24f83
children 74f436e856ff
files sat/plugins/plugin_pubsub_cache.py
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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"
                 )