Use IPFS as universal fallback for content lookup

When content isn't found in local cache, fetch directly from IPFS
using the CID. IPFS is the source of truth for all content-addressed data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-12 21:20:28 +00:00
parent a4bf0eae24
commit faf794ef35

View File

@@ -496,13 +496,27 @@ class L1CacheManager:
if legacy_path.exists() and legacy_path.is_file():
return legacy_path
# Try to recover from IPFS if we have a CID
ipfs_cid = self._get_ipfs_cid_from_index(cid)
if ipfs_cid:
logger.info(f"Recovering from IPFS: {cid[:16]}... ({ipfs_cid})")
# Fetch from IPFS - this is the source of truth for all content
if self._is_ipfs_cid(cid):
logger.info(f"get_by_cid: Fetching from IPFS: {cid[:16]}...")
recovery_path = self.legacy_dir / cid
if ipfs_client.get_file(ipfs_cid, recovery_path):
logger.info(f"Recovered from IPFS: {recovery_path}")
recovery_path.parent.mkdir(parents=True, exist_ok=True)
if ipfs_client.get_file(cid, str(recovery_path)):
logger.info(f"get_by_cid: Fetched from IPFS: {recovery_path}")
self._set_content_index(cid, cid)
return recovery_path
else:
logger.warning(f"get_by_cid: IPFS fetch failed for {cid[:16]}...")
# Also try with a mapped IPFS CID if different from cid
ipfs_cid = self._get_ipfs_cid_from_index(cid)
if ipfs_cid and ipfs_cid != cid:
logger.info(f"get_by_cid: Fetching from IPFS via mapping: {ipfs_cid[:16]}...")
recovery_path = self.legacy_dir / cid
recovery_path.parent.mkdir(parents=True, exist_ok=True)
if ipfs_client.get_file(ipfs_cid, str(recovery_path)):
logger.info(f"get_by_cid: Fetched from IPFS: {recovery_path}")
return recovery_path
return recovery_path
return None