Skip to content

Commit 8fc46ab

Browse files
committed
web/builds: add crate_version_exists
As per suggestion on #2534, although `id` was ambiguous thus using `count(*)`.
1 parent 1018223 commit 8fc46ab

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/web/builds.rs

Lines changed: 23 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,34 @@ 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 COUNT(*) as "count!"
133+
FROM releases
134+
INNER JOIN crates ON crates.id = releases.crate_id
135+
WHERE crates.name = $1 AND releases.version = $2"#,
136+
name,
137+
version.to_string(),
138+
)
139+
.fetch_one(&mut *conn)
140+
.await?;
141+
Ok(row.count > 0)
142+
}
143+
144+
async fn build_trigger_check(
145+
conn: DbConnection,
146+
name: &String,
147+
version: &Version,
130148
build_queue: &Arc<BuildQueue>,
131149
) -> AxumResult<impl IntoResponse> {
132-
let _ = CrateDetails::new(&mut *conn, &name, &version, None, vec![])
133-
.await?
134-
.ok_or(AxumNope::VersionNotFound)?;
150+
if !crate_version_exists(conn, name, version).await? {
151+
return Err(AxumNope::VersionNotFound);
152+
}
135153

136154
let crate_version_is_in_queue = spawn_blocking({
137155
let name = name.clone();

0 commit comments

Comments
 (0)