feat(aggregation): Implement hash-based summary cache
This commit is contained in:
+11
-1
@@ -27,6 +27,9 @@ import ast
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Callable, Any
|
||||
from src.summary_cache import SummaryCache, get_file_hash
|
||||
|
||||
_summary_cache = SummaryCache()
|
||||
|
||||
# ------------------------------------------------------------------ per-type extractors
|
||||
|
||||
@@ -153,10 +156,17 @@ def summarise_file(path: Path, content: str) -> str:
|
||||
Return a compact markdown summary string for a single file.
|
||||
`content` is the already-read file text (or an error string).
|
||||
"""
|
||||
content_hash = get_file_hash(content)
|
||||
cached = _summary_cache.get_summary(str(path), content_hash)
|
||||
if cached:
|
||||
return cached
|
||||
|
||||
suffix = path.suffix.lower() if hasattr(path, "suffix") else ""
|
||||
fn = _SUMMARISERS.get(suffix, _summarise_generic)
|
||||
try:
|
||||
return fn(path, content)
|
||||
summary = fn(path, content)
|
||||
_summary_cache.set_summary(str(path), content_hash, summary)
|
||||
return summary
|
||||
except Exception as e:
|
||||
return f"_Summariser error: {e}_"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user