Skip to content

Commit eb72599

Browse files
committed
release-time in sitemap is not nullable so we don't have to handle NULL
1 parent 4a1f478 commit eb72599

4 files changed

+16
-30
lines changed

.sqlx/query-33fd4ac8d3abdd7d240187e6a834ab8f2384521b036e24ba01501eb7d499e65d.json renamed to .sqlx/query-65b0ead56880b369931c3a5ec324910dde51096de4ee2ad868cc5025161ab466.json

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

src/web/build_details.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
2-
db::Pool,
32
impl_axum_webpage,
43
web::{
54
error::{AxumNope, AxumResult},
5+
extractors::DbConnection,
66
file::File,
77
MetaData,
88
},
@@ -40,14 +40,12 @@ impl_axum_webpage! {
4040

4141
pub(crate) async fn build_details_handler(
4242
Path((name, version, id)): Path<(String, String, String)>,
43-
Extension(pool): Extension<Pool>,
43+
mut conn: DbConnection,
4444
Extension(config): Extension<Arc<Config>>,
4545
Extension(storage): Extension<Arc<AsyncStorage>>,
4646
) -> AxumResult<impl IntoResponse> {
4747
let id: i32 = id.parse().map_err(|_| AxumNope::BuildNotFound)?;
4848

49-
let mut conn = pool.get_async().await?;
50-
5149
let row = sqlx::query!(
5250
"SELECT
5351
builds.rustc_version,

src/web/releases.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,7 @@ impl_axum_webpage! {
618618
ReleaseActivity = "releases/activity.html",
619619
}
620620

621-
pub(crate) async fn activity_handler(
622-
Extension(pool): Extension<Pool>,
623-
) -> AxumResult<impl IntoResponse> {
624-
let mut conn = pool
625-
.get_async()
626-
.await
627-
.context("can't get pool connection")?;
628-
621+
pub(crate) async fn activity_handler(mut conn: DbConnection) -> AxumResult<impl IntoResponse> {
629622
let rows: Vec<_> = sqlx::query!(
630623
r#"WITH dates AS (
631624
-- we need this series so that days in the statistic that don't have any releases are included

src/web/sitemap.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
utils::{get_config, spawn_blocking, ConfigName},
66
web::{
77
error::{AxumNope, AxumResult},
8+
extractors::DbConnection,
89
AxumErrorPage,
910
},
1011
Config,
@@ -56,7 +57,7 @@ impl_axum_webpage! {
5657

5758
pub(crate) async fn sitemap_handler(
5859
Path(letter): Path<String>,
59-
Extension(pool): Extension<Pool>,
60+
mut conn: DbConnection,
6061
) -> AxumResult<impl IntoResponse> {
6162
if letter.len() != 1 {
6263
return Err(AxumNope::ResourceNotFound);
@@ -66,19 +67,17 @@ pub(crate) async fn sitemap_handler(
6667
}
6768
}
6869

69-
let mut conn = pool.get_async().await?;
70-
7170
let releases: Vec<_> = sqlx::query!(
72-
"SELECT crates.name,
71+
r#"SELECT crates.name,
7372
releases.target_name,
74-
MAX(releases.release_time) as release_time
73+
MAX(releases.release_time) as "release_time!"
7574
FROM crates
7675
INNER JOIN releases ON releases.crate_id = crates.id
7776
WHERE
7877
rustdoc_status = true AND
7978
crates.name ILIKE $1
8079
GROUP BY crates.name, releases.target_name
81-
",
80+
"#,
8281
format!("{letter}%"),
8382
)
8483
.fetch(&mut *conn)
@@ -87,15 +86,11 @@ pub(crate) async fn sitemap_handler(
8786
target_name: row.target_name,
8887
last_modified: row
8988
.release_time
90-
.map(|release_time| {
91-
// On Aug 27 2022 we added `<link rel="canonical">` to all pages,
92-
// so they should all get recrawled if they haven't been since then.
93-
release_time
94-
.max(Utc.with_ymd_and_hms(2022, 8, 28, 0, 0, 0).unwrap())
95-
.format("%+")
96-
.to_string()
97-
})
98-
.unwrap_or_default(),
89+
// On Aug 27 2022 we added `<link rel="canonical">` to all pages,
90+
// so they should all get recrawled if they haven't been since then.
91+
.max(Utc.with_ymd_and_hms(2022, 8, 28, 0, 0, 0).unwrap())
92+
.format("%+")
93+
.to_string(),
9994
})
10095
.try_collect()
10196
.await?;

0 commit comments

Comments
 (0)