Fix cache logic bug that caused all files to be incorrectly marked as processed

This commit is contained in:
Jarian Cottingham 2026-02-02 10:17:06 -06:00
parent 218cad82cc
commit 35d8f44ee8

View File

@ -24,7 +24,11 @@ class CacheManager:
try:
if os.path.exists(self.cache_file):
with open(self.cache_file, 'r', encoding='utf-8') as f:
return json.load(f)
cache_data = json.load(f)
# Ensure the cache has the correct structure
if "processed_files" not in cache_data:
cache_data["processed_files"] = {}
return cache_data
else:
# Create empty cache file if it doesn't exist
cache_data = {
@ -59,11 +63,14 @@ class CacheManager:
def is_processed(self, file_path: str) -> bool:
"""Check if a file has been processed."""
return file_path in self.cache
return file_path in self.cache.get("processed_files", {})
def mark_processed(self, file_path: str, status: str = "processed") -> None:
"""Mark a file as processed."""
self.cache[file_path] = {
# Ensure we're using the correct cache structure
if "processed_files" not in self.cache:
self.cache["processed_files"] = {}
self.cache["processed_files"][file_path] = {
"processed_date": datetime.now().isoformat(),
"status": status,
"last_updated": datetime.now().isoformat()
@ -72,13 +79,13 @@ class CacheManager:
def get_processed_files(self) -> List[str]:
"""Get list of all processed files."""
return list(self.cache.keys())
return list(self.cache.get("processed_files", {}).keys())
def get_cache_stats(self) -> Dict:
"""Get cache statistics."""
return {
"total_files": len(self.cache),
"processed_files": len(self.cache),
"total_files": len(self.cache.get("processed_files", {})),
"processed_files": len(self.cache.get("processed_files", {})),
"cache_file": self.cache_file
}