mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-24 06:34:09 +00:00
Enhance VFS watch functionality and introduce recording mode
- Updated the `watch` method in `VfsBackend` to accept a `recursive` parameter, allowing for more flexible directory watching. - Implemented a recording mode in the `Vfs` struct to track accessed paths without immediately watching them, improving performance during read operations. - Added tests to verify the behavior of the new recording mode and ensure correct path tracking. - Enhanced the `StdBackend` and `NoopBackend` implementations to support the updated watch functionality. These changes aim to improve the VFS's ability to manage file system events and enhance user control over watching behavior.
This commit is contained in:
parent
bfb5815f5e
commit
2ea1d49316
8 changed files with 486 additions and 56 deletions
|
|
@ -19,7 +19,7 @@ use crate::{
|
|||
apply_patch_set, compute_patch_set, AppliedPatchSet, InstanceContext, InstanceSnapshot,
|
||||
PatchSet, RojoTree,
|
||||
},
|
||||
snapshot_middleware::snapshot_from_vfs,
|
||||
snapshot_middleware::{is_script_relevant_path, snapshot_from_vfs},
|
||||
};
|
||||
|
||||
/// Set to `true` to validate on plugin connect (useful for testing, do not enable on production).
|
||||
|
|
@ -131,7 +131,7 @@ pub struct ServeSession {
|
|||
|
||||
/// Collect all filesystem paths reachable from the project tree's `$path`
|
||||
/// entries, then read file contents in parallel.
|
||||
fn prefetch_project_files(project: &Project) -> io::Result<PrefetchCache> {
|
||||
fn prefetch_project_files(project: &Project, sync_scripts_only: bool) -> io::Result<PrefetchCache> {
|
||||
use rayon::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use walkdir::WalkDir;
|
||||
|
|
@ -200,6 +200,7 @@ fn prefetch_project_files(project: &Project) -> io::Result<PrefetchCache> {
|
|||
let file_data: Vec<_> = entries
|
||||
.par_iter()
|
||||
.filter(|e| e.file_type().is_file())
|
||||
.filter(|e| !sync_scripts_only || is_script_relevant_path(e.path()))
|
||||
.filter_map(|e| {
|
||||
let path = e.path().to_path_buf();
|
||||
std::fs::read(&path).ok().map(|c| (path, c))
|
||||
|
|
@ -266,10 +267,11 @@ impl ServeSession {
|
|||
log::trace!("Starting new ServeSession at path {}", start_path.display());
|
||||
|
||||
let root_project = Project::load_initial_project(vfs, start_path)?;
|
||||
let sync_scripts_only = root_project.sync_scripts_only.unwrap_or(false);
|
||||
|
||||
if std::env::var("ATLAS_SEQUENTIAL").is_err() {
|
||||
let prefetch_start = Instant::now();
|
||||
match prefetch_project_files(&root_project) {
|
||||
match prefetch_project_files(&root_project, sync_scripts_only) {
|
||||
Ok(cache) => {
|
||||
log::debug!(
|
||||
"Prefetch total: {} files in {:.1?}",
|
||||
|
|
@ -286,7 +288,11 @@ impl ServeSession {
|
|||
|
||||
let mut tree = RojoTree::new(InstanceSnapshot::new());
|
||||
let root_id = tree.get_root_id();
|
||||
let instance_context = InstanceContext::new();
|
||||
let mut instance_context = InstanceContext::new();
|
||||
instance_context.sync_scripts_only = sync_scripts_only;
|
||||
|
||||
vfs.set_watch_recursive(false);
|
||||
vfs.start_watch_recording();
|
||||
|
||||
let snap_start = Instant::now();
|
||||
log::trace!("Generating snapshot of instances from VFS");
|
||||
|
|
@ -303,6 +309,28 @@ impl ServeSession {
|
|||
apply_patch_set(&mut tree, patch_set);
|
||||
log::debug!("Patch computed + applied in {:.1?}", patch_start.elapsed());
|
||||
|
||||
if let Some(recorded_paths) = vfs.take_recorded_paths() {
|
||||
let dir_count = recorded_paths.iter().filter(|p| p.is_dir()).count();
|
||||
for path in &recorded_paths {
|
||||
if path.is_dir() {
|
||||
let _ = vfs.watch(path);
|
||||
}
|
||||
}
|
||||
let mut path_roots = Vec::new();
|
||||
collect_path_roots(
|
||||
&root_project.tree,
|
||||
root_project.folder_location(),
|
||||
&mut path_roots,
|
||||
);
|
||||
for root in &path_roots {
|
||||
let _ = vfs.watch(root);
|
||||
}
|
||||
log::debug!(
|
||||
"Selective watching: {} directories watched (non-recursive)",
|
||||
dir_count + path_roots.len(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok((root_project, tree))
|
||||
}
|
||||
|
||||
|
|
@ -356,6 +384,7 @@ impl ServeSession {
|
|||
root_project.file_location.clone(),
|
||||
critical_error_receiver,
|
||||
git_repo_root.clone(),
|
||||
root_project.sync_scripts_only.unwrap_or(false),
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue