diff --git a/backend/app/data/cache.py b/backend/app/data/cache.py index 9fa43f3..56774b7 100644 --- a/backend/app/data/cache.py +++ b/backend/app/data/cache.py @@ -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""" diff --git a/backend/app/git/branches/checkout.py b/backend/app/git/branches/checkout.py index a814bcf..6899a61 100644 --- a/backend/app/git/branches/checkout.py +++ b/backend/app/git/branches/checkout.py @@ -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}", diff --git a/backend/app/git/operations/delete.py b/backend/app/git/operations/delete.py index 681b63b..88c89ef 100644 --- a/backend/app/git/operations/delete.py +++ b/backend/app/git/operations/delete.py @@ -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 diff --git a/backend/app/git/operations/merge.py b/backend/app/git/operations/merge.py index b998fc9..e7390d7 100644 --- a/backend/app/git/operations/merge.py +++ b/backend/app/git/operations/merge.py @@ -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: diff --git a/backend/app/git/operations/pull.py b/backend/app/git/operations/pull.py index ad2a638..d6f4721 100644 --- a/backend/app/git/operations/pull.py +++ b/backend/app/git/operations/pull.py @@ -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: diff --git a/backend/app/git/operations/resolve.py b/backend/app/git/operations/resolve.py index c0b08e8..87bb1f8 100644 --- a/backend/app/git/operations/resolve.py +++ b/backend/app/git/operations/resolve.py @@ -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} diff --git a/backend/app/git/operations/revert.py b/backend/app/git/operations/revert.py index 220386f..4badb52 100644 --- a/backend/app/git/operations/revert.py +++ b/backend/app/git/operations/revert.py @@ -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 diff --git a/backend/app/git/repo/clone.py b/backend/app/git/repo/clone.py index e85df67..2c99dd3 100644 --- a/backend/app/git/repo/clone.py +++ b/backend/app/git/repo/clone.py @@ -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" diff --git a/backend/app/git/repo/unlink.py b/backend/app/git/repo/unlink.py index 747cd0a..1d54263 100644 --- a/backend/app/git/repo/unlink.py +++ b/backend/app/git/repo/unlink.py @@ -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: