comparison sat/plugins/plugin_pubsub_cache.py @ 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 ffa8c8c78115
children 74f436e856ff
comparison
equal deleted inserted replaced
3758:b7cef1b24f83 3759:c4881833cf8a
275 275
276 try: 276 try:
277 await self.host.checkFeatures( 277 await self.host.checkFeatures(
278 client, [rsm.NS_RSM, self._p.DISCO_RSM], pubsub_node.service 278 client, [rsm.NS_RSM, self._p.DISCO_RSM], pubsub_node.service
279 ) 279 )
280 except error.StanzaError as e:
281 if e.condition == "service-unavailable":
282 log.warning(
283 "service is hidding disco infos, we'll only cache latest 20 items"
284 )
285 items, __ = await client.pubsub_client.items(
286 pubsub_node.service, pubsub_node.name, maxItems=20
287 )
288 await self.cacheItems(
289 client, pubsub_node, items
290 )
291 else:
292 raise e
280 except exceptions.FeatureNotFound: 293 except exceptions.FeatureNotFound:
281 log.warning( 294 log.warning(
282 f"service {service} doesn't handle Result Set Management " 295 f"service {service} doesn't handle Result Set Management "
283 "(XEP-0059), we'll only cache latest 20 items" 296 "(XEP-0059), we'll only cache latest 20 items"
284 ) 297 )
491 extra = {} 504 extra = {}
492 if "mam" in extra: 505 if "mam" in extra:
493 raise NotImplementedError("MAM queries are not supported yet") 506 raise NotImplementedError("MAM queries are not supported yet")
494 if max_items is None and rsm_request is None: 507 if max_items is None and rsm_request is None:
495 max_items = 20 508 max_items = 20
496 if max_items is not None: 509 pubsub_items, metadata = await self.host.memory.storage.getItems(
510 node, max_items=max_items, item_ids=item_ids,
511 order_by=extra.get(C.KEY_ORDER_BY)
512 )
513 elif max_items is not None:
497 if rsm_request is not None: 514 if rsm_request is not None:
498 raise exceptions.InternalError( 515 raise exceptions.InternalError(
499 "Pubsub max items and RSM must not be used at the same time" 516 "Pubsub max items and RSM must not be used at the same time"
500 ) 517 )
501 elif item_ids is None: 518 elif item_ids:
502 raise exceptions.InternalError( 519 raise exceptions.InternalError(
503 "Pubsub max items and item IDs must not be used at the same time" 520 "Pubsub max items and item IDs must not be used at the same time"
504 ) 521 )
505 pubsub_items, metadata = await self.host.memory.storage.getItems( 522 pubsub_items, metadata = await self.host.memory.storage.getItems(
506 node, max_items=max_items, order_by=extra.get(C.KEY_ORDER_BY) 523 node, max_items=max_items, order_by=extra.get(C.KEY_ORDER_BY)