11use anyhow:: Context ;
2- use crates_io:: models:: { update_default_version, verify_default_version} ;
3- use crates_io:: tasks:: spawn_blocking;
2+ use crates_io:: models:: { async_update_default_version, async_verify_default_version} ;
43use crates_io:: { db, schema:: crates} ;
54use diesel:: prelude:: * ;
6- use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
7- use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
5+ use diesel_async:: RunQueryDsl ;
86use indicatif:: { ProgressBar , ProgressIterator , ProgressStyle } ;
97
108#[ derive( clap:: Parser , Debug , Eq , PartialEq ) ]
@@ -28,25 +26,21 @@ pub async fn run(command: Command) -> anyhow::Result<()> {
2826 . await
2927 . context ( "Failed to load crates" ) ?;
3028
31- let mut conn = AsyncConnectionWrapper :: < AsyncPgConnection > :: from ( conn) ;
32- spawn_blocking ( move || {
33- let pb = ProgressBar :: new ( crate_ids. len ( ) as u64 ) ;
34- pb. set_style ( ProgressStyle :: with_template (
35- "{bar:60} ({pos}/{len}, ETA {eta})" ,
36- ) ?) ;
29+ let pb = ProgressBar :: new ( crate_ids. len ( ) as u64 ) ;
30+ pb. set_style ( ProgressStyle :: with_template (
31+ "{bar:60} ({pos}/{len}, ETA {eta})" ,
32+ ) ?) ;
3733
38- for crate_id in crate_ids. into_iter ( ) . progress_with ( pb. clone ( ) ) {
39- let func = match command {
40- Command :: Update => update_default_version ,
41- Command :: Verify => verify_default_version ,
42- } ;
34+ for crate_id in crate_ids. into_iter ( ) . progress_with ( pb. clone ( ) ) {
35+ let result = match command {
36+ Command :: Update => async_update_default_version ( crate_id , & mut conn ) . await ,
37+ Command :: Verify => async_verify_default_version ( crate_id , & mut conn ) . await ,
38+ } ;
4339
44- if let Err ( error) = func ( crate_id, & mut conn) {
45- pb. suspend ( || warn ! ( %crate_id, %error, "Failed to update the default version" ) ) ;
46- }
40+ if let Err ( error) = result {
41+ pb. suspend ( || warn ! ( %crate_id, %error, "Failed to update the default version" ) ) ;
4742 }
43+ }
4844
49- Ok ( ( ) )
50- } )
51- . await ?
45+ Ok ( ( ) )
5246}
0 commit comments