comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3851:ef824b1091f3

component AP gateway: get items when not found in cache in `apGetLocalObject`: rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 4479f6074bc8
children 384ad98ea9fe
comparison
equal deleted inserted replaced
3850:4479f6074bc8 3851:ef824b1091f3
387 node = self._m.namespace 387 node = self._m.namespace
388 cached_node = await self.host.memory.storage.getPubsubNode( 388 cached_node = await self.host.memory.storage.getPubsubNode(
389 self.client, author_jid, node 389 self.client, author_jid, node
390 ) 390 )
391 if not cached_node: 391 if not cached_node:
392 raise exceptions.NotFound 392 log.debug(f"node {node!r} at {author_jid} is not found in cache")
393 cached_items, __ = await self.host.memory.storage.getItems( 393 found_item = None
394 cached_node, item_ids=[item_id] 394 else:
395 ) 395 cached_items, __ = await self.host.memory.storage.getItems(
396 if not cached_items: 396 cached_node, item_ids=[item_id]
397 raise exceptions.NotFound(
398 f"item {item_id!r} is not found in cache"
399 ) 397 )
398 if not cached_items:
399 log.debug(
400 f"item {item_id!r} of {node!r} at {author_jid} is not found in "
401 "cache"
402 )
403 found_item = None
404 else:
405 found_item = cached_items[0].data
406
407 if found_item is None:
408 # the node is not in cache, we have to make a request to retrieve the item
409 # if doesn't exist, getItems will raise a NotFound exception
410 found_items, __ = await self._p.getItems(
411 self.client, author_jid, node, item_ids=[item_id]
412 )
413 found_item = found_items[0]
414
400 mb_data = await self._m.item2mbdata( 415 mb_data = await self._m.item2mbdata(
401 self.client, cached_items[0].data, author_jid, node 416 self.client, found_item, author_jid, node
402 ) 417 )
403 ap_item = await self.mbdata2APitem(self.client, mb_data) 418 ap_item = await self.mbdata2APitem(self.client, mb_data)
404 # the URL must return the object and not the activity 419 # the URL must return the object and not the activity
405 return ap_item["object"] 420 return ap_item["object"]
406 else: 421 else: