Skip to content

Commit 005a072

Browse files
committed
web/builds: add crate_version_exists to query the database directly
1 parent 464a4c0 commit 005a072

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/web/builds.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
impl_axum_webpage,
1010
utils::spawn_blocking,
1111
web::{
12-
crate_details::CrateDetails,
1312
error::AxumResult,
1413
extractors::{DbConnection, Path},
1514
match_version, MetaData, ReqVersion,
@@ -123,15 +122,35 @@ pub(crate) async fn build_list_json_handler(
123122
.into_response())
124123
}
125124

126-
async fn build_trigger_check(
125+
async fn crate_version_exists(
127126
mut conn: DbConnection,
128127
name: &String,
129128
version: &Version,
129+
) -> Result<bool, anyhow::Error> {
130+
let row = sqlx::query!(
131+
r#"
132+
SELECT 1 as "dummy"
133+
FROM releases
134+
INNER JOIN crates ON crates.id = releases.crate_id
135+
WHERE crates.name = $1 AND releases.version = $2
136+
LIMIT 1"#,
137+
name,
138+
version.to_string(),
139+
)
140+
.fetch_optional(&mut *conn)
141+
.await?;
142+
Ok(row.is_some())
143+
}
144+
145+
async fn build_trigger_check(
146+
conn: DbConnection,
147+
name: &String,
148+
version: &Version,
130149
build_queue: &Arc<BuildQueue>,
131150
) -> AxumResult<impl IntoResponse> {
132-
let _ = CrateDetails::new(&mut *conn, &name, &version, None, vec![])
133-
.await?
134-
.ok_or(AxumNope::VersionNotFound)?;
151+
if !crate_version_exists(conn, name, version).await? {
152+
return Err(AxumNope::VersionNotFound);
153+
}
135154

136155
let crate_version_is_in_queue = spawn_blocking({
137156
let name = name.clone();

src/web/crate_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl CrateDetails {
126126
.unwrap())
127127
}
128128

129-
pub(crate) async fn new(
129+
async fn new(
130130
conn: &mut sqlx::PgConnection,
131131
name: &str,
132132
version: &Version,

0 commit comments

Comments
 (0)