Implement RefPathIndex for efficient handling of Rojo_Ref_* attributes

- Introduced the `RefPathIndex` structure to map `Rojo_Ref_*` attribute values to their corresponding meta/model file paths, enabling O(affected_files) lookups during instance renaming.
- Updated `ChangeProcessor`, `ServeSession`, and `ApiService` to utilize the new index for managing reference paths, improving performance and reliability during rename operations.
- Enhanced the `update_ref_paths_after_rename` function to leverage the index for efficient file updates, reducing the need for full tree scans.
- Added comprehensive tests for `RefPathIndex` to ensure correct functionality and robustness against edge cases.

These changes significantly enhance the efficiency of reference path management in the synchronization system.
This commit is contained in:
Joe 2026-02-14 13:28:29 -06:00
parent ca2a938902
commit faa12dc573
6 changed files with 445 additions and 103 deletions

View file

@ -108,6 +108,10 @@ pub struct ServeSession {
/// the appropriate counter, each suppressed VFS event decrements it.
#[allow(dead_code)]
suppressed_paths: Arc<Mutex<std::collections::HashMap<std::path::PathBuf, (usize, usize)>>>,
/// Index of meta/model files that contain `Rojo_Ref_*` attributes.
/// Shared between ApiService (writes) and ChangeProcessor (rename updates).
ref_path_index: Arc<Mutex<crate::RefPathIndex>>,
}
impl ServeSession {
@ -153,6 +157,7 @@ impl ServeSession {
let (tree_mutation_sender, tree_mutation_receiver) = crossbeam_channel::unbounded();
let suppressed_paths = Arc::new(Mutex::new(std::collections::HashMap::new()));
let ref_path_index = Arc::new(Mutex::new(crate::RefPathIndex::new()));
log::trace!("Starting ChangeProcessor");
let change_processor = ChangeProcessor::start(
@ -161,6 +166,7 @@ impl ServeSession {
Arc::clone(&message_queue),
tree_mutation_receiver,
Arc::clone(&suppressed_paths),
Arc::clone(&ref_path_index),
root_project.folder_location().to_path_buf(),
critical_error_receiver,
);
@ -175,6 +181,7 @@ impl ServeSession {
tree_mutation_sender,
vfs,
suppressed_paths,
ref_path_index,
})
}
@ -199,6 +206,12 @@ impl ServeSession {
Arc::clone(&self.suppressed_paths)
}
/// Returns a handle to the Ref path index, shared between ApiService
/// and ChangeProcessor for efficient rename path updates.
pub fn ref_path_index(&self) -> Arc<Mutex<crate::RefPathIndex>> {
Arc::clone(&self.ref_path_index)
}
#[allow(unused)]
pub fn vfs(&self) -> &Vfs {
&self.vfs