Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- 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