diff --git a/sat/plugins/plugin_comp_ap_gateway/__init__.py b/sat/plugins/plugin_comp_ap_gateway/__init__.py index 5f1477bf..162c2c60 100644 --- a/sat/plugins/plugin_comp_ap_gateway/__init__.py +++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py @@ -389,16 +389,31 @@ class APGateway: self.client, author_jid, node ) if not cached_node: - raise exceptions.NotFound - cached_items, __ = await self.host.memory.storage.getItems( - cached_node, item_ids=[item_id] - ) - if not cached_items: - raise exceptions.NotFound( - f"item {item_id!r} is not found in cache" + log.debug(f"node {node!r} at {author_jid} is not found in cache") + found_item = None + else: + cached_items, __ = await self.host.memory.storage.getItems( + cached_node, item_ids=[item_id] ) + if not cached_items: + log.debug( + f"item {item_id!r} of {node!r} at {author_jid} is not found in " + "cache" + ) + found_item = None + else: + found_item = cached_items[0].data + + if found_item is None: + # the node is not in cache, we have to make a request to retrieve the item + # if doesn't exist, getItems will raise a NotFound exception + found_items, __ = await self._p.getItems( + self.client, author_jid, node, item_ids=[item_id] + ) + found_item = found_items[0] + mb_data = await self._m.item2mbdata( - self.client, cached_items[0].data, author_jid, node + self.client, found_item, author_jid, node ) ap_item = await self.mbdata2APitem(self.client, mb_data) # the URL must return the object and not the activity