Skip to content

Commit 882076d

Browse files
SimplicityGuyclaude
andcommitted
fix(extractor): cache file list to avoid double scraping Discogs website
When FORCE_REPROCESS is set, list_s3_files was called twice per run: once in process_discogs_data to detect the version, and again inside download_discogs_data. This caused two full scrapes of the Discogs website on every startup. Added cached_files field to Downloader so the result of the first scrape is reused within the same process_discogs_data invocation. The cache is naturally reset on each run since a new Downloader is created per invocation, ensuring periodic checks always fetch fresh data from the website. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 76242a7 commit 882076d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

extractor/src/downloader.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct Downloader {
2727
base_url: String,
2828
pub state_marker: Option<StateMarker>,
2929
pub marker_path: Option<PathBuf>,
30+
cached_files: Option<Vec<S3FileInfo>>,
3031
}
3132

3233
impl Downloader {
@@ -39,7 +40,7 @@ impl Downloader {
3940
pub async fn new_with_base_url(output_directory: PathBuf, base_url: String) -> Result<Self> {
4041
let metadata = load_metadata(&output_directory)?;
4142

42-
Ok(Self { output_directory, metadata, base_url, state_marker: None, marker_path: None })
43+
Ok(Self { output_directory, metadata, base_url, state_marker: None, marker_path: None, cached_files: None })
4344
}
4445

4546
/// Set the state marker for tracking download progress
@@ -210,7 +211,12 @@ impl Downloader {
210211
Ok(ids)
211212
}
212213

213-
pub async fn list_s3_files(&self) -> Result<Vec<S3FileInfo>> {
214+
pub async fn list_s3_files(&mut self) -> Result<Vec<S3FileInfo>> {
215+
if let Some(ref cached) = self.cached_files {
216+
debug!("📋 Using cached file list ({} files)", cached.len());
217+
return Ok(cached.clone());
218+
}
219+
214220
info!("🔍 Listing available files from Discogs website...");
215221

216222
// Scrape file list from Discogs website instead of S3 listing
@@ -221,6 +227,7 @@ impl Downloader {
221227
let files: Vec<S3FileInfo> = ids_map.into_values().flat_map(|files| files.into_iter()).collect();
222228

223229
info!("Found {} relevant files from website", files.len());
230+
self.cached_files = Some(files.clone());
224231
Ok(files)
225232
}
226233

0 commit comments

Comments
 (0)