From 5ee22f72017b483720c0826f80025f8d07a9c357 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 28 Aug 2025 01:45:14 +0930 Subject: [PATCH] fix(cache): reload cache on git operations --- backend/app/git/branches/checkout.py | 6 ++++++ backend/app/git/operations/delete.py | 5 +++++ backend/app/git/operations/merge.py | 5 +++++ backend/app/git/operations/pull.py | 5 +++++ backend/app/git/operations/resolve.py | 5 +++++ backend/app/git/operations/revert.py | 8 ++++++++ backend/app/git/repo/clone.py | 5 +++++ backend/app/git/repo/unlink.py | 6 ++++++ 8 files changed, 45 insertions(+) diff --git a/backend/app/git/branches/checkout.py b/backend/app/git/branches/checkout.py index f688dd7..a814bcf 100644 --- a/backend/app/git/branches/checkout.py +++ b/backend/app/git/branches/checkout.py @@ -44,6 +44,12 @@ def checkout_branch(repo_path, branch_name): return False, f"Branch '{branch_name}' does not exist locally or in any remote." logger.debug(f"Successfully checked out branch: {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() + return True, { "message": f"Checked out branch: {branch_name}", "current_branch": branch_name diff --git a/backend/app/git/operations/delete.py b/backend/app/git/operations/delete.py index 2713a77..681b63b 100644 --- a/backend/app/git/operations/delete.py +++ b/backend/app/git/operations/delete.py @@ -11,6 +11,11 @@ def delete_file(repo_path, file_path): if os.path.exists(full_file_path): os.remove(full_file_path) + + # Reload cache after file deletion + from ...data.cache import data_cache + data_cache.initialize() + message = f"File {file_path} has been deleted." return True, message else: diff --git a/backend/app/git/operations/merge.py b/backend/app/git/operations/merge.py index be34700..b998fc9 100644 --- a/backend/app/git/operations/merge.py +++ b/backend/app/git/operations/merge.py @@ -60,6 +60,11 @@ def finalize_merge(repo) -> Dict[str, Any]: if status_manager: status_manager.update_remote_status() + # 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 + return {'success': True, 'message': 'Merge completed successfully'} except git.GitCommandError as e: logger.error(f"Git command error during commit: {str(e)}") diff --git a/backend/app/git/operations/pull.py b/backend/app/git/operations/pull.py index 61202d0..ad2a638 100644 --- a/backend/app/git/operations/pull.py +++ b/backend/app/git/operations/pull.py @@ -35,6 +35,11 @@ def pull_branch(repo_path, branch_name): if status_manager: status_manager.update_remote_status() + # 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 + # ------------------------------- # *** "On pull" ARR import logic using new importer: # 1) Query all ARR configs that have sync_method="pull" diff --git a/backend/app/git/operations/resolve.py b/backend/app/git/operations/resolve.py index 363d718..c0b08e8 100644 --- a/backend/app/git/operations/resolve.py +++ b/backend/app/git/operations/resolve.py @@ -310,6 +310,11 @@ def resolve_conflicts( logger.debug(f"File status: {item}") logger.debug("=======================================") + # Reload cache after conflict resolution + from ...data.cache import data_cache + logger.info("Reloading data cache after conflict resolution") + data_cache.initialize() + return {'success': True, 'results': results} except Exception as e: diff --git a/backend/app/git/operations/revert.py b/backend/app/git/operations/revert.py index 77a5bc3..220386f 100644 --- a/backend/app/git/operations/revert.py +++ b/backend/app/git/operations/revert.py @@ -51,6 +51,10 @@ def revert_file(repo_path, file_path): repo.git.restore('--staged', "--", file_path) message = f"File {file_path} has been reverted." + # Reload cache after revert + from ...data.cache import data_cache + data_cache.initialize() + return True, message except git.exc.GitCommandError as e: @@ -98,6 +102,10 @@ def revert_all(repo_path): message += f" and {len(untracked_files)} new file(s) have been removed" message += "." + # Reload cache after reverting all + from ...data.cache import data_cache + data_cache.initialize() + return True, message except git.exc.GitCommandError as e: diff --git a/backend/app/git/repo/clone.py b/backend/app/git/repo/clone.py index 801f82a..e85df67 100644 --- a/backend/app/git/repo/clone.py +++ b/backend/app/git/repo/clone.py @@ -116,6 +116,11 @@ def clone_repository(repo_url, repo_path): logger.info("Removing backup directory") shutil.rmtree(backup_dir) + # Reload cache after clone operation + from ...data.cache import data_cache + logger.info("Reloading data cache after clone") + data_cache.initialize() + 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 a2a3395..747cd0a 100644 --- a/backend/app/git/repo/unlink.py +++ b/backend/app/git/repo/unlink.py @@ -68,6 +68,12 @@ def unlink_repository(repo_path, remove_files=False): save_settings({'gitRepo': None}) logger.info("Updated settings to remove git information") + # Reload cache if files were removed + if remove_files: + from ...data.cache import data_cache + logger.info("Reloading data cache after removing repository files") + data_cache.initialize() + return True, "Repository successfully unlinked" except Exception as e: logger.error(f"Error unlinking repository: {str(e)}", exc_info=True)