Skip to content

Commit 7ae9cd2

Browse files
committed
⚡ Bolt: Fix N+1 query in Deep Architectural Synthesis
1 parent f0bad29 commit 7ae9cd2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • src/ledgermind/core/reasoning/enrichment

src/ledgermind/core/reasoning/enrichment/facade.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,10 @@ def _execute_consolidation(self, fids: List[str], memory: Any, parent_fid: str):
650650
logger.info(f" - Starting Deep Architectural Synthesis for {len(fids)} documents...")
651651

652652
docs_full = []
653+
# ⚡ Bolt: Prevent N+1 query problem by batch fetching metadata instead of looping over individual IDs
654+
meta_batch = {m['fid']: m for m in memory.semantic.meta.get_batch_by_fids(fids) if m}
653655
for fid in fids:
654-
meta = memory.semantic.meta.get_by_fid(fid)
656+
meta = meta_batch.get(fid)
655657
if meta:
656658
full_body = f"FID: {fid}\nTITLE: {meta.get('title')}\nRATIONALE: {meta.get('rationale', '')}\nCONTENT: {meta.get('content', '')}"
657659
docs_full.append(full_body)

0 commit comments

Comments
 (0)