refactor: optimize config_observer with caching and redundant I/O#139
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces caching for application configuration and SSH hosts data to improve efficiency and consistency across the codebase. It uses
OnceLockandRwLockto cache loaded values and provides explicit refresh functions to update the caches when changes are made. Additionally, it refactors the SSH key loading logic for clarity and efficiency.Caching and Consistency Improvements:
AppConfigand SSH hosts usingOnceLock<RwLock<...>>, and updated all relevant functions (load_app_config,save_app_config,load_hosts, etc.) to use these caches for faster repeated access and to ensure consistency across the application. [1] [2] [3] [4]refresh_app_configandrefresh_hostsfunctions to reload configuration and hosts from disk and update the caches, ensuring that changes on disk are reflected in memory. [1] [2]Refactoring and Code Quality:
load_ssh_keysto use iterator chains withfilter_mapfor improved readability and efficiency, and to return early if the SSH directory does not exist.get_home_dirfunction, reducing redundant calls toUserDirs::new()and improving performance.Cache Synchronization on Write Operations:
save_app_config,add_host_to_config, anddelete_host_from_configto update the relevant caches after writing to disk, ensuring in-memory data stays in sync with file changes. [1] [2] [3]