Skip to content

Commit

Permalink
fix(core): sort projects after updating from context
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Sep 23, 2024
1 parent 7af099c commit 8440a2c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/nx/src/native/workspace/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down Expand Up @@ -278,11 +278,14 @@ impl WorkspaceContext {
"adding {} updated files to project files",
updated_files.len()
);

let mut updated_projects = HashSet::<&str>::new();
for updated_file in updated_files.into_iter() {
let file = updated_file.0;
let hash = updated_file.1;
if let Some(project_files) = find_project_for_path(&file, &project_root_mappings)
.and_then(|project| project_files_map.get_mut(project))
let project = find_project_for_path(&file, &project_root_mappings);
if let Some(project_files) =
project.and_then(|project| project_files_map.get_mut(project))
{
trace!("{file:?} was found in a project");
if let Some(file) = project_files.iter_mut().find(|f| f.file == file) {
Expand All @@ -291,6 +294,7 @@ impl WorkspaceContext {
} else {
trace!("{file:?} was not part of a project, adding to project files");
project_files.push(FileData { file, hash });
updated_projects.insert(project.expect("Project already exists"));
}
} else {
trace!("{file:?} was not found in any project, updating global files");
Expand Down Expand Up @@ -321,6 +325,21 @@ impl WorkspaceContext {
}
}

// sort the updated projects after deletion
// projects that have deleted files were not added to `updated_projects` set because deletion doesnt change the determinism
// but if there were any files deleted from projects, the sort should be faster becaues there potentially could be less files to sort
for updated_project in updated_projects {
trace!(updated_project, "sorting updated project");
if let Some(project_files) = project_files_map.get_mut(updated_project) {
// if the project files are less than 500, then parallel sort has too much overhead to actually be faster
if cfg!(target_arch = "wasm32") || project_files.len() < 500 {
project_files.sort();
} else {
project_files.par_sort();
}
}
}

let non_project_files = global_files
.into_iter()
.map(|(file, hash)| FileData { file, hash })
Expand Down

0 comments on commit 8440a2c

Please sign in to comment.