fix(cache): reload cache on git operations

This commit is contained in:
Sam Chau
2025-08-28 01:45:14 +09:30
parent 61854e3d02
commit 5ee22f7201
8 changed files with 45 additions and 0 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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)}")

View File

@@ -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"

View File

@@ -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:

View File

@@ -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:

View File

@@ -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"

View File

@@ -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)