|
1 | 1 | use crate::{
|
2 |
| - db::Pool, |
3 | 2 | impl_axum_webpage,
|
4 |
| - utils::spawn_blocking, |
5 | 3 | web::{
|
6 | 4 | error::{AxumNope, AxumResult},
|
| 5 | + extractors::DbConnection, |
7 | 6 | file::File,
|
8 | 7 | MetaData,
|
9 | 8 | },
|
@@ -41,58 +40,48 @@ impl_axum_webpage! {
|
41 | 40 |
|
42 | 41 | pub(crate) async fn build_details_handler(
|
43 | 42 | Path((name, version, id)): Path<(String, String, String)>,
|
44 |
| - Extension(pool): Extension<Pool>, |
| 43 | + mut conn: DbConnection, |
45 | 44 | Extension(config): Extension<Arc<Config>>,
|
46 | 45 | Extension(storage): Extension<Arc<AsyncStorage>>,
|
47 | 46 | ) -> AxumResult<impl IntoResponse> {
|
48 | 47 | let id: i32 = id.parse().map_err(|_| AxumNope::BuildNotFound)?;
|
49 | 48 |
|
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 { |
80 | 70 | output
|
81 | 71 | } 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); |
84 | 73 | let file = File::from_path(&storage, &path, &config).await?;
|
85 | 74 | String::from_utf8(file.0.content).context("non utf8")?
|
86 | 75 | };
|
87 | 76 |
|
88 | 77 | Ok(BuildDetailsPage {
|
89 |
| - metadata, |
| 78 | + metadata: MetaData::from_crate(&mut conn, &name, &version, &version).await?, |
90 | 79 | build_details: BuildDetails {
|
91 | 80 | 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, |
96 | 85 | output,
|
97 | 86 | },
|
98 | 87 | use_direct_platform_links: true,
|
|
0 commit comments