search: Add heuristic for discarding matching of binary files (#23581)

Fixes #23398 
Closes #23398

We'll bail on searches of files that we know are binary (thus even if we
were to find a match in them, they'd be thrown away by buffer loader).

Release Notes:

- Improved project search performance in worktrees with binary files
This commit is contained in:
Piotr Osiewicz 2025-01-23 23:15:58 +01:00 committed by GitHub
parent 35ddb432b3
commit fb63f61755
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 7 deletions

View file

@ -101,7 +101,7 @@ pub trait Fs: Send + Sync {
self.remove_file(path, options).await
}
async fn open_handle(&self, path: &Path) -> Result<Arc<dyn FileHandle>>;
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>>;
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read + Send + Sync>>;
async fn load(&self, path: &Path) -> Result<String> {
Ok(String::from_utf8(self.load_bytes(path).await?)?)
}
@ -499,7 +499,7 @@ impl Fs for RealFs {
Ok(())
}
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>> {
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read + Send + Sync>> {
Ok(Box::new(std::fs::File::open(path)?))
}
@ -1746,7 +1746,7 @@ impl Fs for FakeFs {
Ok(())
}
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>> {
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read + Send + Sync>> {
let bytes = self.load_internal(path).await?;
Ok(Box::new(io::Cursor::new(bytes)))
}