Skip to content

Commit 7ec8e96

Browse files
committed
fix(dna): use architecture_patterns column for DNA cache
- Fixed save_to_cache to use existing table schema - Fixed load_from_cache to read from architecture_patterns JSONB - DNA stored as {codebase_dna: {...}} inside architecture_patterns
1 parent 54039c1 commit 7ec8e96

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

backend/services/dna_extractor.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -552,22 +552,17 @@ def extract_dna(self, repo_path: str, repo_id: str) -> CodebaseDNA:
552552
return dna
553553

554554
def save_to_cache(self, repo_id: str, dna: CodebaseDNA) -> bool:
555-
"""Save DNA to database cache"""
555+
"""Save DNA to database cache using architecture_patterns column"""
556556
try:
557-
data = {
558-
'repo_id': repo_id,
559-
'dna_data': dna.to_dict(),
560-
'dna_markdown': dna.to_markdown(),
561-
}
557+
# Store DNA in the architecture_patterns JSONB column
558+
dna_data = {'codebase_dna': dna.to_dict()}
562559

563-
# Upsert to repository_insights or a new table
564560
self.supabase.client.table('repository_insights').upsert(
565561
{
566562
'repo_id': repo_id,
567-
'insight_type': 'codebase_dna',
568-
'data': dna.to_dict(),
563+
'architecture_patterns': dna_data,
569564
},
570-
on_conflict='repo_id,insight_type'
565+
on_conflict='repo_id'
571566
).execute()
572567

573568
logger.info("DNA saved to cache", repo_id=repo_id)
@@ -579,12 +574,17 @@ def save_to_cache(self, repo_id: str, dna: CodebaseDNA) -> bool:
579574
def load_from_cache(self, repo_id: str) -> Optional[CodebaseDNA]:
580575
"""Load DNA from database cache"""
581576
try:
582-
result = self.supabase.client.table('repository_insights').select('*').eq(
583-
'repo_id', repo_id
584-
).eq('insight_type', 'codebase_dna').execute()
577+
result = self.supabase.client.table('repository_insights').select(
578+
'architecture_patterns'
579+
).eq('repo_id', repo_id).execute()
585580

586-
if result.data:
587-
data = result.data[0]['data']
581+
if result.data and result.data[0].get('architecture_patterns'):
582+
arch_patterns = result.data[0]['architecture_patterns']
583+
data = arch_patterns.get('codebase_dna')
584+
585+
if not data:
586+
return None
587+
588588
# Reconstruct CodebaseDNA from dict
589589
dna = CodebaseDNA(
590590
repo_id=data['repo_id'],

0 commit comments

Comments
 (0)