fix(cache): force reinitialize on git ops

This commit is contained in:
Sam Chau
2025-08-28 13:24:43 +09:30
parent 5ee22f7201
commit 9e5e5ce523
9 changed files with 18 additions and 14 deletions

View File

@@ -20,18 +20,22 @@ class DataCache:
self._lock = threading.RLock()
self._initialized = False
def initialize(self):
"""Load all data into memory on startup"""
def initialize(self, force_reload=False):
"""Load all data into memory on startup
Args:
force_reload: If True, force a reload even if already initialized
"""
with self._lock:
if self._initialized:
if self._initialized and not force_reload:
return
logger.info("Initializing data cache...")
logger.info("Initializing data cache..." if not force_reload else "Reloading data cache...")
for category in self._cache.keys():
self._load_category(category)
self._initialized = True
logger.info("Data cache initialized successfully")
logger.info("Data cache initialized successfully" if not force_reload else "Data cache reloaded successfully")
def _load_category(self, category: str):
"""Load all items from a category into cache"""

View File

@@ -48,7 +48,7 @@ def checkout_branch(repo_path, branch_name):
# Reload cache after branch checkout since files may have changed
from ...data.cache import data_cache
logger.info("Reloading data cache after branch checkout")
data_cache.initialize()
data_cache.initialize(force_reload=True)
return True, {
"message": f"Checked out branch: {branch_name}",

View File

@@ -14,7 +14,7 @@ def delete_file(repo_path, file_path):
# Reload cache after file deletion
from ...data.cache import data_cache
data_cache.initialize()
data_cache.initialize(force_reload=True)
message = f"File {file_path} has been deleted."
return True, message

View File

@@ -63,7 +63,7 @@ def finalize_merge(repo) -> Dict[str, Any]:
# Reload cache for modified data files
from ...data.cache import data_cache
logger.info("Reloading data cache after merge completion")
data_cache.initialize() # This will reload all data
data_cache.initialize(force_reload=True) # This will reload all data
return {'success': True, 'message': 'Merge completed successfully'}
except git.GitCommandError as e:

View File

@@ -38,7 +38,7 @@ def pull_branch(repo_path, branch_name):
# Reload cache for updated data files
from ...data.cache import data_cache
logger.info("Reloading data cache after pull")
data_cache.initialize() # This will reload all data
data_cache.initialize(force_reload=True) # This will reload all data
# -------------------------------
# *** "On pull" ARR import logic using new importer:

View File

@@ -313,7 +313,7 @@ def resolve_conflicts(
# Reload cache after conflict resolution
from ...data.cache import data_cache
logger.info("Reloading data cache after conflict resolution")
data_cache.initialize()
data_cache.initialize(force_reload=True)
return {'success': True, 'results': results}

View File

@@ -53,7 +53,7 @@ def revert_file(repo_path, file_path):
# Reload cache after revert
from ...data.cache import data_cache
data_cache.initialize()
data_cache.initialize(force_reload=True)
return True, message
@@ -104,7 +104,7 @@ def revert_all(repo_path):
# Reload cache after reverting all
from ...data.cache import data_cache
data_cache.initialize()
data_cache.initialize(force_reload=True)
return True, message

View File

@@ -119,7 +119,7 @@ def clone_repository(repo_url, repo_path):
# Reload cache after clone operation
from ...data.cache import data_cache
logger.info("Reloading data cache after clone")
data_cache.initialize()
data_cache.initialize(force_reload=True)
logger.info("Clone operation completed successfully")
return True, "Repository cloned and local files merged successfully"

View File

@@ -72,7 +72,7 @@ def unlink_repository(repo_path, remove_files=False):
if remove_files:
from ...data.cache import data_cache
logger.info("Reloading data cache after removing repository files")
data_cache.initialize()
data_cache.initialize(force_reload=True)
return True, "Repository successfully unlinked"
except Exception as e: