Skip to content

Commit

Permalink
Skip empty SourceMap uploads
Browse files Browse the repository at this point in the history
This avoids uploading empty (but still unique until we pull in getsentry/symbolic#778) artifact / release bundles if all the source maps included in them have already been uploaded before.
  • Loading branch information
Swatinem committed Mar 30, 2023
1 parent 8e03a4a commit 40ff371
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/utils/file_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn upload_files_chunked(
));

upload_chunks(&chunks, options, progress_style)?;
println!("{} Uploaded release files to Sentry", style(">").dim(),);
println!("{} Uploaded release files to Sentry", style(">").dim());

let progress_style = ProgressStyle::default_spinner().template("{spinner} Processing files...");

Expand Down Expand Up @@ -443,6 +443,8 @@ fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result

bundle.finish()?;

pb.finish_with_duration("Bundling");

println!(
"{} Bundled {} {} for upload",
style(">").dim(),
Expand All @@ -453,8 +455,6 @@ fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result
}
);

pb.finish_with_duration("Bundling");

Ok(archive)
}

Expand Down
28 changes: 19 additions & 9 deletions src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,18 @@ impl SourceMapProcessor {
Ok(())
}

fn flag_uploaded_sources(&mut self, context: &UploadContext<'_>) {
/// Flags the collected sources whether they have already been uploaded before
/// (based on their checksum), and returns the number of files that *do* need an upload.
fn flag_uploaded_sources(&mut self, context: &UploadContext<'_>) -> usize {
let mut files_needing_upload = self.sources.len();

// TODO: this endpoint does not exist for non release based uploads
if !context.dedupe {
return;
return files_needing_upload;
}
let release = match context.release {
Some(release) => release,
None => return,
None => return files_needing_upload,
};

let mut sources_checksums: Vec<_> = self
Expand All @@ -618,29 +622,35 @@ impl SourceMapProcessor {
release,
&sources_checksums,
) {
let already_uploaded_checksums: Vec<_> = artifacts
.iter()
let already_uploaded_checksums: HashSet<_> = artifacts
.into_iter()
.filter_map(|artifact| Digest::from_str(&artifact.sha1).ok())
.collect();

for mut source in self.sources.values_mut() {
if let Ok(checksum) = source.checksum() {
if already_uploaded_checksums.contains(&checksum) {
source.already_uploaded = true;
files_needing_upload -= 1;
}
}
}
}
files_needing_upload
}

/// Uploads all files
pub fn upload(&mut self, context: &UploadContext<'_>) -> Result<()> {
initialize_legacy_release_upload(context)?;
self.flush_pending_sources();
self.flag_uploaded_sources(context);
let mut uploader = FileUpload::new(context);
uploader.files(&self.sources);
uploader.upload()?;
let files_needing_upload = self.flag_uploaded_sources(context);
if files_needing_upload > 0 {
let mut uploader = FileUpload::new(context);
uploader.files(&self.sources);
uploader.upload()?;
} else {
println!("{} Nothing to upload", style(">").dim());
}
self.dump_log("Source Map Upload Report");
Ok(())
}
Expand Down

0 comments on commit 40ff371

Please sign in to comment.