Skip to content

Commit

Permalink
release-time in sitemap is not nullable so we don't have to handle NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Nov 15, 2023
1 parent 4a1f478 commit eb72599
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/web/build_details.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
db::Pool,
impl_axum_webpage,
web::{
error::{AxumNope, AxumResult},
extractors::DbConnection,
file::File,
MetaData,
},
Expand Down Expand Up @@ -40,14 +40,12 @@ impl_axum_webpage! {

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

let mut conn = pool.get_async().await?;

let row = sqlx::query!(
"SELECT
builds.rustc_version,
Expand Down
9 changes: 1 addition & 8 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,7 @@ impl_axum_webpage! {
ReleaseActivity = "releases/activity.html",
}

pub(crate) async fn activity_handler(
Extension(pool): Extension<Pool>,
) -> AxumResult<impl IntoResponse> {
let mut conn = pool
.get_async()
.await
.context("can't get pool connection")?;

pub(crate) async fn activity_handler(mut conn: DbConnection) -> AxumResult<impl IntoResponse> {
let rows: Vec<_> = sqlx::query!(
r#"WITH dates AS (
-- we need this series so that days in the statistic that don't have any releases are included
Expand Down
25 changes: 10 additions & 15 deletions src/web/sitemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
utils::{get_config, spawn_blocking, ConfigName},
web::{
error::{AxumNope, AxumResult},
extractors::DbConnection,
AxumErrorPage,
},
Config,
Expand Down Expand Up @@ -56,7 +57,7 @@ impl_axum_webpage! {

pub(crate) async fn sitemap_handler(
Path(letter): Path<String>,
Extension(pool): Extension<Pool>,
mut conn: DbConnection,
) -> AxumResult<impl IntoResponse> {
if letter.len() != 1 {
return Err(AxumNope::ResourceNotFound);
Expand All @@ -66,19 +67,17 @@ pub(crate) async fn sitemap_handler(
}
}

let mut conn = pool.get_async().await?;

let releases: Vec<_> = sqlx::query!(
"SELECT crates.name,
r#"SELECT crates.name,
releases.target_name,
MAX(releases.release_time) as release_time
MAX(releases.release_time) as "release_time!"
FROM crates
INNER JOIN releases ON releases.crate_id = crates.id
WHERE
rustdoc_status = true AND
crates.name ILIKE $1
GROUP BY crates.name, releases.target_name
",
"#,
format!("{letter}%"),
)
.fetch(&mut *conn)
Expand All @@ -87,15 +86,11 @@ pub(crate) async fn sitemap_handler(
target_name: row.target_name,
last_modified: row
.release_time
.map(|release_time| {
// On Aug 27 2022 we added `<link rel="canonical">` to all pages,
// so they should all get recrawled if they haven't been since then.
release_time
.max(Utc.with_ymd_and_hms(2022, 8, 28, 0, 0, 0).unwrap())
.format("%+")
.to_string()
})
.unwrap_or_default(),
// On Aug 27 2022 we added `<link rel="canonical">` to all pages,
// so they should all get recrawled if they haven't been since then.
.max(Utc.with_ymd_and_hms(2022, 8, 28, 0, 0, 0).unwrap())
.format("%+")
.to_string(),
})
.try_collect()
.await?;
Expand Down

0 comments on commit eb72599

Please sign in to comment.