File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 11use crate :: { db, schema:: version_downloads} ;
22
3- use crate :: tasks:: spawn_blocking;
43use diesel:: prelude:: * ;
4+ use diesel_async:: scoped_futures:: ScopedFutureExt ;
5+ use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
56use rand:: rngs:: StdRng ;
67use rand:: { Rng , SeedableRng } ;
78
@@ -16,15 +17,13 @@ pub struct Opts {
1617}
1718
1819pub async fn run ( opts : Opts ) -> anyhow:: Result < ( ) > {
19- spawn_blocking ( move || {
20- let mut conn = db:: oneoff_connection ( ) ?;
21- conn. transaction ( |conn| update ( opts, conn) ) ?;
22- Ok ( ( ) )
23- } )
24- . await
20+ let mut conn = db:: oneoff_async_connection ( ) . await ?;
21+ conn. transaction ( |conn| update ( opts, conn) . scope_boxed ( ) )
22+ . await ?;
23+ Ok ( ( ) )
2524}
2625
27- fn update ( opts : Opts , conn : & mut PgConnection ) -> QueryResult < ( ) > {
26+ async fn update ( opts : Opts , conn : & mut AsyncPgConnection ) -> QueryResult < ( ) > {
2827 use diesel:: dsl:: * ;
2928
3029 for id in opts. version_ids {
@@ -40,7 +39,8 @@ fn update(opts: Opts, conn: &mut PgConnection) -> QueryResult<()> {
4039 version_downloads:: downloads. eq ( dls) ,
4140 version_downloads:: date. eq ( date ( now - day. days ( ) ) ) ,
4241 ) )
43- . execute ( conn) ?;
42+ . execute ( conn)
43+ . await ?;
4444 }
4545 }
4646 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments