Skip to content

Commit 114faa4

Browse files
committed
start migration more web endpoints to sqlx
1 parent 4af81bf commit 114faa4

14 files changed

+394
-188
lines changed

.sqlx/query-5d8e187d604de870d347be77abae3a272114732644975e9dbf396f5ffe689f6b.json

+71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-65b0ead56880b369931c3a5ec324910dde51096de4ee2ad868cc5025161ab466.json

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-908827d37c731be4a6611eacd2e53aa03ae0b38047e0e58c034a3d34f8e29631.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-96817014a0af7e5946ecd00000ff08b5deaa12d85e1e0bb7bd845beafb0f2702.json

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-a7cbfecb1e270232061de05fa4a53f926d9e289dcb4b03cba3e3eeebce74dfe0.json

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/db/types.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use postgres_types::{FromSql, ToSql};
22
use serde::Serialize;
33

4-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, FromSql, ToSql)]
4+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, FromSql, ToSql, sqlx::Type)]
55
#[postgres(name = "feature")]
66
pub struct Feature {
77
pub(crate) name: String,
@@ -17,3 +17,9 @@ impl Feature {
1717
self.name.starts_with('_')
1818
}
1919
}
20+
21+
impl sqlx::postgres::PgHasArrayType for Feature {
22+
fn array_type_info() -> sqlx::postgres::PgTypeInfo {
23+
sqlx::postgres::PgTypeInfo::with_name("_feature")
24+
}
25+
}

src/web/build_details.rs

+29-40
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::{
2-
db::Pool,
32
impl_axum_webpage,
4-
utils::spawn_blocking,
53
web::{
64
error::{AxumNope, AxumResult},
5+
extractors::DbConnection,
76
file::File,
87
MetaData,
98
},
@@ -41,58 +40,48 @@ impl_axum_webpage! {
4140

4241
pub(crate) async fn build_details_handler(
4342
Path((name, version, id)): Path<(String, String, String)>,
44-
Extension(pool): Extension<Pool>,
43+
mut conn: DbConnection,
4544
Extension(config): Extension<Arc<Config>>,
4645
Extension(storage): Extension<Arc<AsyncStorage>>,
4746
) -> AxumResult<impl IntoResponse> {
4847
let id: i32 = id.parse().map_err(|_| AxumNope::BuildNotFound)?;
4948

50-
let (row, output, metadata) = spawn_blocking(move || {
51-
let mut conn = pool.get()?;
52-
let row = conn
53-
.query_opt(
54-
"SELECT
55-
builds.rustc_version,
56-
builds.docsrs_version,
57-
builds.build_status,
58-
builds.build_time,
59-
builds.output,
60-
releases.default_target
61-
FROM builds
62-
INNER JOIN releases ON releases.id = builds.rid
63-
INNER JOIN crates ON releases.crate_id = crates.id
64-
WHERE builds.id = $1 AND crates.name = $2 AND releases.version = $3",
65-
&[&id, &name, &version],
66-
)?
67-
.ok_or(AxumNope::BuildNotFound)?;
68-
69-
let output: Option<String> = row.get("output");
70-
71-
Ok((
72-
row,
73-
output,
74-
MetaData::from_crate(&mut conn, &name, &version, &version)?,
75-
))
76-
})
77-
.await?;
78-
79-
let output = if let Some(output) = output {
49+
let row = sqlx::query!(
50+
"SELECT
51+
builds.rustc_version,
52+
builds.docsrs_version,
53+
builds.build_status,
54+
builds.build_time,
55+
builds.output,
56+
releases.default_target
57+
FROM builds
58+
INNER JOIN releases ON releases.id = builds.rid
59+
INNER JOIN crates ON releases.crate_id = crates.id
60+
WHERE builds.id = $1 AND crates.name = $2 AND releases.version = $3",
61+
id,
62+
name,
63+
version,
64+
)
65+
.fetch_optional(&mut *conn)
66+
.await?
67+
.ok_or(AxumNope::BuildNotFound)?;
68+
69+
let output = if let Some(output) = row.output {
8070
output
8171
} else {
82-
let target: String = row.get("default_target");
83-
let path = format!("build-logs/{id}/{target}.txt");
72+
let path = format!("build-logs/{id}/{}.txt", row.default_target);
8473
let file = File::from_path(&storage, &path, &config).await?;
8574
String::from_utf8(file.0.content).context("non utf8")?
8675
};
8776

8877
Ok(BuildDetailsPage {
89-
metadata,
78+
metadata: MetaData::from_crate(&mut conn, &name, &version, &version).await?,
9079
build_details: BuildDetails {
9180
id,
92-
rustc_version: row.get("rustc_version"),
93-
docsrs_version: row.get("docsrs_version"),
94-
build_status: row.get("build_status"),
95-
build_time: row.get("build_time"),
81+
rustc_version: row.rustc_version,
82+
docsrs_version: row.docsrs_version,
83+
build_status: row.build_status,
84+
build_time: row.build_time,
9685
output,
9786
},
9887
use_direct_platform_links: true,

0 commit comments

Comments
 (0)