# HG changeset patch # User Goffi # Date 1657796130 -7200 # Node ID ef824b1091f34185bcc7cd04b94ae4d74f46abb3 # Parent 4479f6074bc81fc2b5cd31225581042b68d48718 component AP gateway: get items when not found in cache in `apGetLocalObject`: rel 370 diff -r 4479f6074bc8 -r ef824b1091f3 sat/plugins/plugin_comp_ap_gateway/__init__.py --- a/sat/plugins/plugin_comp_ap_gateway/__init__.py Thu Jul 14 12:55:30 2022 +0200 +++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py Thu Jul 14 12:55:30 2022 +0200 @@ -389,16 +389,31 @@ 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