Skip to content

Commit 16c0f62

Browse files
Nemo157syphar
authored andcommitted
Read rustc_verison directly from builds instead of release
1 parent 8af340e commit 16c0f62

8 files changed

+63
-120
lines changed

.sqlx/query-2b8b1aae3740a05cb7179be9c7d5af30e8362c3cba0b07bc18fa32ff1a2232cc.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-97deab9378fe8c0f7bac04def1007c23305a12c892a794e5161b47b839c3183c.json renamed to .sqlx/query-790af2d57b8d036f14a9a8874c2fc94c4cd6b3d4acd5eb2e67c1fb5729b5471a.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-9f1181d51fde9d63ffafbf397e5a5af66cdd3764872cd5a3a401ffd5ca075de8.json

Lines changed: 0 additions & 77 deletions
This file was deleted.

.sqlx/query-5d8e187d604de870d347be77abae3a272114732644975e9dbf396f5ffe689f6b.json renamed to .sqlx/query-d471c22a41a040f720ac678b085265f616eef21a09ffaaa243fc26f107ad6c87.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/crate_details.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl CrateDetails {
159159
releases.license,
160160
releases.documentation_url,
161161
releases.default_target,
162-
releases.doc_rustc_version,
162+
builds.rustc_version as "rustc_version?",
163163
doc_coverage.total_items,
164164
doc_coverage.documented_items,
165165
doc_coverage.total_items_needing_examples,
@@ -202,7 +202,11 @@ impl CrateDetails {
202202
default_target: krate.default_target,
203203
doc_targets: MetaData::parse_doc_targets(krate.doc_targets),
204204
yanked: krate.yanked,
205-
rustdoc_css_file: get_correct_docsrs_style_file(&krate.doc_rustc_version)?,
205+
rustdoc_css_file: krate
206+
.rustc_version
207+
.as_deref()
208+
.map(get_correct_docsrs_style_file)
209+
.transpose()?,
206210
};
207211

208212
let mut crate_details = CrateDetails {

src/web/mod.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,19 @@ pub(crate) struct MetaData {
620620
pub(crate) yanked: bool,
621621
/// CSS file to use depending on the rustdoc version used to generate this version of this
622622
/// crate.
623-
pub(crate) rustdoc_css_file: String,
623+
pub(crate) rustdoc_css_file: Option<String>,
624624
}
625625

626626
impl MetaData {
627+
#[fn_error_context::context("getting metadata for {name} {version}")]
627628
async fn from_crate(
628629
conn: &mut sqlx::PgConnection,
629630
name: &str,
630631
version: &Version,
631632
req_version: Option<ReqVersion>,
632633
) -> Result<MetaData> {
633-
sqlx::query!(
634-
"SELECT
634+
let row = sqlx::query!(
635+
r#"SELECT
635636
crates.name,
636637
releases.version,
637638
releases.description,
@@ -640,17 +641,24 @@ impl MetaData {
640641
releases.default_target,
641642
releases.doc_targets,
642643
releases.yanked,
643-
releases.doc_rustc_version
644+
builds.rustc_version as "rustc_version?"
644645
FROM releases
645646
INNER JOIN crates ON crates.id = releases.crate_id
646-
WHERE crates.name = $1 AND releases.version = $2",
647+
LEFT JOIN LATERAL (
648+
SELECT * FROM builds
649+
WHERE builds.rid = releases.id
650+
ORDER BY builds.build_time
651+
DESC LIMIT 1
652+
) AS builds ON true
653+
WHERE crates.name = $1 AND releases.version = $2"#,
647654
name,
648655
version.to_string(),
649656
)
650-
.fetch_optional(&mut *conn)
657+
.fetch_one(&mut *conn)
651658
.await
652-
.context("error fetching crate metadata")?
653-
.map(|row| MetaData {
659+
.context("error fetching crate metadata")?;
660+
661+
Ok(MetaData {
654662
name: row.name,
655663
version: version.clone(),
656664
req_version: req_version.unwrap_or_else(|| ReqVersion::Exact(version.clone())),
@@ -660,9 +668,13 @@ impl MetaData {
660668
default_target: row.default_target,
661669
doc_targets: MetaData::parse_doc_targets(row.doc_targets),
662670
yanked: row.yanked,
663-
rustdoc_css_file: get_correct_docsrs_style_file(&row.doc_rustc_version).unwrap(),
671+
// rustdoc_css_file: get_correct_docsrs_style_file(&row.doc_rustc_version).unwrap(),
672+
rustdoc_css_file: row
673+
.rustc_version
674+
.as_deref()
675+
.map(get_correct_docsrs_style_file)
676+
.transpose()?,
664677
})
665-
.ok_or_else(|| anyhow!("missing metadata for {} {}", name, version))
666678
}
667679

668680
fn parse_doc_targets(targets: Value) -> Vec<String> {
@@ -1068,7 +1080,7 @@ mod test {
10681080
"arm64-unknown-linux-gnu".to_string(),
10691081
],
10701082
yanked: false,
1071-
rustdoc_css_file: "rustdoc.css".to_string(),
1083+
rustdoc_css_file: Some("rustdoc.css".to_string()),
10721084
};
10731085

10741086
let correct_json = json!({
@@ -1152,7 +1164,7 @@ mod test {
11521164
default_target: "x86_64-unknown-linux-gnu".to_string(),
11531165
doc_targets: vec![],
11541166
yanked: false,
1155-
rustdoc_css_file: "rustdoc.css".to_string(),
1167+
rustdoc_css_file: Some("rustdoc.css".to_string()),
11561168
},
11571169
);
11581170
Ok(())

src/web/source.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
db::Pool,
44
impl_axum_webpage,
55
storage::PathNotFoundError,
6-
utils::get_correct_docsrs_style_file,
76
web::{
87
cache::CachePolicy, error::AxumNope, extractors::Path, file::File as DbFile,
98
headers::CanonicalUrl, MetaData, ReqVersion,
@@ -76,16 +75,7 @@ impl FileList {
7675
folder: &str,
7776
) -> Result<Option<FileList>> {
7877
let row = match sqlx::query!(
79-
"SELECT crates.name,
80-
releases.version,
81-
releases.description,
82-
releases.target_name,
83-
releases.rustdoc_status,
84-
releases.files,
85-
releases.default_target,
86-
releases.doc_targets,
87-
releases.yanked,
88-
releases.doc_rustc_version
78+
"SELECT releases.files
8979
FROM releases
9080
INNER JOIN crates ON crates.id = releases.crate_id
9181
WHERE crates.name = $1 AND releases.version = $2",
@@ -147,18 +137,7 @@ impl FileList {
147137
});
148138

149139
Ok(Some(FileList {
150-
metadata: MetaData {
151-
name: row.name,
152-
version: version.clone(),
153-
req_version: req_version.unwrap_or_else(|| ReqVersion::Exact(version.clone())),
154-
description: row.description,
155-
target_name: Some(row.target_name),
156-
rustdoc_status: row.rustdoc_status,
157-
default_target: row.default_target,
158-
doc_targets: MetaData::parse_doc_targets(row.doc_targets),
159-
yanked: row.yanked,
160-
rustdoc_css_file: get_correct_docsrs_style_file(&row.doc_rustc_version)?,
161-
},
140+
metadata: MetaData::from_crate(conn, name, version, req_version).await?,
162141
files: file_list,
163142
}))
164143
} else {

templates/rustdoc/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{%- import "macros.html" as macros -%}
2+
{% if metadata.rustdoc_css_file %}
23
<link rel="stylesheet" href="/-/static/{{metadata.rustdoc_css_file}}?{{ docsrs_version() | slugify }}" media="all" />
4+
{% endif %}
35

46
<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />
57

0 commit comments

Comments
 (0)