@@ -6,7 +6,6 @@ use super::version_and_crate;
66use crate :: app:: AppState ;
77use crate :: models:: VersionDownload ;
88use crate :: schema:: * ;
9- use crate :: tasks:: spawn_blocking;
109use crate :: util:: diesel:: prelude:: * ;
1110use crate :: util:: errors:: { version_not_found, AppResult } ;
1211use crate :: util:: { redirect, RequestUtils } ;
@@ -16,7 +15,6 @@ use axum::response::{IntoResponse, Response};
1615use axum_extra:: json;
1716use axum_extra:: response:: ErasedJson ;
1817use chrono:: { Duration , NaiveDate , Utc } ;
19- use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
2018use http:: request:: Parts ;
2119
2220/// Handles the `GET /crates/:crate_id/:version/download` route.
@@ -41,33 +39,30 @@ pub async fn downloads(
4139 Path ( ( crate_name, version) ) : Path < ( String , String ) > ,
4240 req : Parts ,
4341) -> AppResult < ErasedJson > {
42+ use diesel_async:: RunQueryDsl ;
43+
4444 if semver:: Version :: parse ( & version) . is_err ( ) {
4545 return Err ( version_not_found ( & crate_name, & version) ) ;
4646 }
4747
4848 let mut conn = app. db_read ( ) . await ?;
4949 let ( version, _) = version_and_crate ( & mut conn, & crate_name, & version) . await ?;
50- spawn_blocking ( move || {
51- use diesel:: RunQueryDsl ;
52-
53- let conn: & mut AsyncConnectionWrapper < _ > = & mut conn. into ( ) ;
5450
55- let cutoff_end_date = req
56- . query ( )
57- . get ( "before_date" )
58- . and_then ( |d| NaiveDate :: parse_from_str ( d, "%F" ) . ok ( ) )
59- . unwrap_or_else ( || Utc :: now ( ) . date_naive ( ) ) ;
60- let cutoff_start_date = cutoff_end_date - Duration :: days ( 89 ) ;
51+ let cutoff_end_date = req
52+ . query ( )
53+ . get ( "before_date" )
54+ . and_then ( |d| NaiveDate :: parse_from_str ( d, "%F" ) . ok ( ) )
55+ . unwrap_or_else ( || Utc :: now ( ) . date_naive ( ) ) ;
56+ let cutoff_start_date = cutoff_end_date - Duration :: days ( 89 ) ;
6157
62- let downloads = VersionDownload :: belonging_to ( & version)
63- . filter ( version_downloads:: date. between ( cutoff_start_date, cutoff_end_date) )
64- . order ( version_downloads:: date)
65- . load ( conn) ?
66- . into_iter ( )
67- . map ( VersionDownload :: into)
68- . collect :: < Vec < EncodableVersionDownload > > ( ) ;
58+ let downloads = VersionDownload :: belonging_to ( & version)
59+ . filter ( version_downloads:: date. between ( cutoff_start_date, cutoff_end_date) )
60+ . order ( version_downloads:: date)
61+ . load ( & mut conn)
62+ . await ?
63+ . into_iter ( )
64+ . map ( VersionDownload :: into)
65+ . collect :: < Vec < EncodableVersionDownload > > ( ) ;
6966
70- Ok ( json ! ( { "version_downloads" : downloads } ) )
71- } )
72- . await ?
67+ Ok ( json ! ( { "version_downloads" : downloads } ) )
7368}
0 commit comments