Improve performance of project panel with many git statuses (#25465)

Closes #ISSUE

Release Notes:

- Improved performance of project panel in large git repositories
This commit is contained in:
Cole Miller 2025-02-24 17:03:52 -05:00 committed by GitHub
parent a78f3cfea2
commit e06666759a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 16 deletions

View file

@ -206,15 +206,19 @@ pub struct RepositoryEntry {
pub current_merge_conflicts: TreeSet<RepoPath>,
}
impl Deref for RepositoryEntry {
type Target = WorkDirectory;
fn deref(&self) -> &Self::Target {
&self.work_directory
}
}
impl RepositoryEntry {
pub fn relativize(&self, path: &Path) -> Result<RepoPath> {
self.work_directory.relativize(path)
}
pub fn unrelativize(&self, path: &RepoPath) -> Option<Arc<Path>> {
self.work_directory.unrelativize(path)
}
pub fn directory_contains(&self, path: impl AsRef<Path>) -> bool {
self.work_directory.directory_contains(path)
}
pub fn branch(&self) -> Option<&Branch> {
self.current_branch.as_ref()
}
@ -2834,7 +2838,7 @@ impl Snapshot {
pub fn repository_for_path(&self, path: &Path) -> Option<&RepositoryEntry> {
self.repositories
.iter()
.filter(|repo| repo.work_directory.directory_contains(path))
.filter(|repo| repo.directory_contains(path))
.last()
}
@ -6023,7 +6027,13 @@ impl<'a> GitTraversal<'a> {
};
// Update our state if we changed repositories.
if reset || self.repo_location.as_ref().map(|(prev_repo, _)| prev_repo) != Some(&repo) {
if reset
|| self
.repo_location
.as_ref()
.map(|(prev_repo, _)| &prev_repo.work_directory)
!= Some(&repo.work_directory)
{
self.repo_location = Some((repo, repo.statuses_by_path.cursor::<PathProgress>(&())));
}