Fix cache logic bug that caused all files to be incorrectly marked as processed
This commit is contained in:
parent
218cad82cc
commit
35d8f44ee8
@ -24,7 +24,11 @@ class CacheManager:
|
|||||||
try:
|
try:
|
||||||
if os.path.exists(self.cache_file):
|
if os.path.exists(self.cache_file):
|
||||||
with open(self.cache_file, 'r', encoding='utf-8') as f:
|
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:
|
else:
|
||||||
# Create empty cache file if it doesn't exist
|
# Create empty cache file if it doesn't exist
|
||||||
cache_data = {
|
cache_data = {
|
||||||
@ -59,11 +63,14 @@ class CacheManager:
|
|||||||
|
|
||||||
def is_processed(self, file_path: str) -> bool:
|
def is_processed(self, file_path: str) -> bool:
|
||||||
"""Check if a file has been processed."""
|
"""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:
|
def mark_processed(self, file_path: str, status: str = "processed") -> None:
|
||||||
"""Mark a file as processed."""
|
"""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(),
|
"processed_date": datetime.now().isoformat(),
|
||||||
"status": status,
|
"status": status,
|
||||||
"last_updated": datetime.now().isoformat()
|
"last_updated": datetime.now().isoformat()
|
||||||
@ -72,13 +79,13 @@ class CacheManager:
|
|||||||
|
|
||||||
def get_processed_files(self) -> List[str]:
|
def get_processed_files(self) -> List[str]:
|
||||||
"""Get list of all processed files."""
|
"""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:
|
def get_cache_stats(self) -> Dict:
|
||||||
"""Get cache statistics."""
|
"""Get cache statistics."""
|
||||||
return {
|
return {
|
||||||
"total_files": len(self.cache),
|
"total_files": len(self.cache.get("processed_files", {})),
|
||||||
"processed_files": len(self.cache),
|
"processed_files": len(self.cache.get("processed_files", {})),
|
||||||
"cache_file": self.cache_file
|
"cache_file": self.cache_file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user