From c61f12dd225ffabd3913aa29adfdf3feb1a62522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Thu, 6 Feb 2025 03:07:05 -0300 Subject: [PATCH] Zeta: Skip opening files redundantly if a license was found (#24357) Release Notes: - N/A --- crates/zeta/src/zeta.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs index c287a30677d33c93f7176d591c7674294ad254da..c20522b00b8610dc3b6dc4c20fc653712a9c0f5b 100644 --- a/crates/zeta/src/zeta.rs +++ b/crates/zeta/src/zeta.rs @@ -957,21 +957,31 @@ impl LicenseDetectionWatcher { let task = if worktree.abs_path().is_file() { Task::ready(()) } else { - let loaded_files_task = futures::future::join_all( - LICENSE_FILES_TO_CHECK - .iter() - .map(|file| worktree.load_file(Path::new(file), cx)), - ); + let loaded_files = LICENSE_FILES_TO_CHECK + .iter() + .map(Path::new) + .map(|file| worktree.load_file(file, cx)) + .collect::>(); cx.background_executor().spawn(async move { - for loaded_file in loaded_files_task.await { - if let Some(content) = loaded_file.log_err() { - if is_license_eligible_for_data_collection(&content.text) { - *is_open_source_tx.borrow_mut() = true; - break; - } + for loaded_file in loaded_files.into_iter() { + let Ok(loaded_file) = loaded_file.await else { + continue; + }; + + let path = &loaded_file.file.path; + if is_license_eligible_for_data_collection(&loaded_file.text) { + log::info!("detected '{path:?}' as open source license"); + *is_open_source_tx.borrow_mut() = true; + } else { + log::info!("didn't detect '{path:?}' as open source license"); } + + // stop on the first license that successfully read + return; } + + log::debug!("didn't find a license file to check, assuming closed source"); }) };