From 35d8f44ee82f48a579d0ab6c6b9c7ce15fc5e2e0 Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Mon, 2 Feb 2026 10:17:06 -0600 Subject: [PATCH] Fix cache logic bug that caused all files to be incorrectly marked as processed --- ai_processor/cache_manager.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ai_processor/cache_manager.py b/ai_processor/cache_manager.py index 4ac38ce..bb26a18 100644 --- a/ai_processor/cache_manager.py +++ b/ai_processor/cache_manager.py @@ -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 }