Skip to content

Conversation

@Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Nov 21, 2024

finally...

now, unfortunately we still have a spawn_blocking() call in the endpoint since I didn't feel comfortable with processing the tarball on the async worker thread, but at least we're not using the AsyncConnectionWrapper wrapper anymore 🎉

This will allow us to throw away a bunch of duplicated code in some of the follow-up PRs :)

@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Nov 21, 2024
@Turbo87 Turbo87 requested a review from a team November 21, 2024 16:27
@codecov
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.94%. Comparing base (df815d7) to head (f0d35ab).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/controllers/krate/publish.rs 97.11% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10041      +/-   ##
==========================================
- Coverage   89.44%   88.94%   -0.51%     
==========================================
  Files         295      295              
  Lines       31475    31477       +2     
==========================================
- Hits        28154    27997     -157     
- Misses       3321     3480     +159     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move back to use diesel::prelude::* and flatten

let (existing_crate, auth) = {
use diesel_async::RunQueryDsl;
let deleted_crate: Option<(String, DateTime<Utc>)> = deleted_crates::table
.filter(canon_crate_name(deleted_crates::name).eq(canon_crate_name(&metadata.name)))
.filter(deleted_crates::available_at.gt(Utc::now()))
.select((deleted_crates::name, deleted_crates::available_at))
.first(&mut conn)
.await
.optional()?;
if let Some(deleted_crate) = deleted_crate {
return Err(bad_request(format!(
"A crate with the name `{}` was recently deleted. Reuse of this name will be available after {}.",
deleted_crate.0,
deleted_crate.1.to_rfc3339_opts(SecondsFormat::Secs, true)
)));
}
// this query should only be used for the endpoint scope calculation
// since a race condition there would only cause `publish-new` instead of
// `publish-update` to be used.
let existing_crate: Option<Crate> = Crate::by_name(&metadata.name)
.first::<Crate>(&mut conn)
.await
.optional()?;
let endpoint_scope = match existing_crate {
Some(_) => EndpointScope::PublishUpdate,
None => EndpointScope::PublishNew,
};
let auth = AuthCheck::default()
.with_endpoint_scope(endpoint_scope)
.for_crate(&metadata.name)
.check(&req, &mut conn)
.await?;
(existing_crate, auth)
};
now that we've converted this file to diesel-async.

@Turbo87 Turbo87 enabled auto-merge (squash) November 22, 2024 08:31
@Turbo87 Turbo87 merged commit e04e4e2 into rust-lang:main Nov 22, 2024
8 checks passed
@Turbo87 Turbo87 deleted the async-publish branch November 22, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants