@@ -6,7 +6,6 @@ use super::version_and_crate;
6
6
use crate :: app:: AppState ;
7
7
use crate :: models:: VersionDownload ;
8
8
use crate :: schema:: * ;
9
- use crate :: tasks:: spawn_blocking;
10
9
use crate :: util:: diesel:: prelude:: * ;
11
10
use crate :: util:: errors:: { version_not_found, AppResult } ;
12
11
use crate :: util:: { redirect, RequestUtils } ;
@@ -16,7 +15,6 @@ use axum::response::{IntoResponse, Response};
16
15
use axum_extra:: json;
17
16
use axum_extra:: response:: ErasedJson ;
18
17
use chrono:: { Duration , NaiveDate , Utc } ;
19
- use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
20
18
use http:: request:: Parts ;
21
19
22
20
/// Handles the `GET /crates/:crate_id/:version/download` route.
@@ -41,33 +39,30 @@ pub async fn downloads(
41
39
Path ( ( crate_name, version) ) : Path < ( String , String ) > ,
42
40
req : Parts ,
43
41
) -> AppResult < ErasedJson > {
42
+ use diesel_async:: RunQueryDsl ;
43
+
44
44
if semver:: Version :: parse ( & version) . is_err ( ) {
45
45
return Err ( version_not_found ( & crate_name, & version) ) ;
46
46
}
47
47
48
48
let mut conn = app. db_read ( ) . await ?;
49
49
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 ( ) ;
54
50
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 ) ;
61
57
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 > > ( ) ;
69
66
70
- Ok ( json ! ( { "version_downloads" : downloads } ) )
71
- } )
72
- . await ?
67
+ Ok ( json ! ( { "version_downloads" : downloads } ) )
73
68
}
0 commit comments