Skip to content

refactor: optimize config_observer with caching and redundant I/O#139

Merged
Cleboost merged 1 commit into
masterfrom
refactor/optimize-config-observer
May 11, 2026
Merged

refactor: optimize config_observer with caching and redundant I/O#139
Cleboost merged 1 commit into
masterfrom
refactor/optimize-config-observer

Conversation

@Cleboost
Copy link
Copy Markdown
Owner

This pull request introduces caching for application configuration and SSH hosts data to improve efficiency and consistency across the codebase. It uses OnceLock and RwLock to 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:

  • Introduced static caches for AppConfig and SSH hosts using OnceLock<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]
  • Added explicit refresh_app_config and refresh_hosts functions 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:

  • Refactored the SSH key loading logic in load_ssh_keys to use iterator chains with filter_map for improved readability and efficiency, and to return early if the SSH directory does not exist.
  • Centralized home directory resolution with a cached get_home_dir function, reducing redundant calls to UserDirs::new() and improving performance.

Cache Synchronization on Write Operations:

  • Updated save_app_config, add_host_to_config, and delete_host_from_config to update the relevant caches after writing to disk, ensuring in-memory data stays in sync with file changes. [1] [2] [3]

@Cleboost Cleboost merged commit 4a826e0 into master May 11, 2026
1 check passed
@Cleboost Cleboost deleted the refactor/optimize-config-observer branch May 11, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant