@@ -249,51 +249,55 @@ pub async fn reverse_dependencies(
249249 Path ( name) : Path < String > ,
250250 req : Parts ,
251251) -> AppResult < Json < Value > > {
252- let conn = app. db_read ( ) . await ?;
253- spawn_blocking ( move || {
254- use diesel:: RunQueryDsl ;
252+ use diesel_async:: RunQueryDsl ;
255253
256- let conn : & mut AsyncConnectionWrapper < _ > = & mut conn . into ( ) ;
254+ let mut conn = app . db_read ( ) . await ? ;
257255
258- let pagination_options = PaginationOptions :: builder ( ) . gather ( & req) ?;
256+ let pagination_options = PaginationOptions :: builder ( ) . gather ( & req) ?;
259257
260- let krate: Crate = Crate :: by_name ( & name)
261- . first ( conn)
262- . optional ( ) ?
263- . ok_or_else ( || crate_not_found ( & name) ) ?;
258+ let krate: Crate = Crate :: by_name ( & name)
259+ . first ( & mut conn)
260+ . await
261+ . optional ( ) ?
262+ . ok_or_else ( || crate_not_found ( & name) ) ?;
264263
265- let ( rev_deps, total) = krate. reverse_dependencies ( conn, pagination_options) ?;
266- let rev_deps: Vec < _ > = rev_deps
267- . into_iter ( )
268- . map ( |dep| EncodableDependency :: from_reverse_dep ( dep, & krate. name ) )
269- . collect ( ) ;
264+ let ( rev_deps, total) = krate
265+ . reverse_dependencies ( & mut conn, pagination_options)
266+ . await ?;
270267
271- let version_ids: Vec < i32 > = rev_deps. iter ( ) . map ( |dep| dep. version_id ) . collect ( ) ;
268+ let rev_deps: Vec < _ > = rev_deps
269+ . into_iter ( )
270+ . map ( |dep| EncodableDependency :: from_reverse_dep ( dep, & krate. name ) )
271+ . collect ( ) ;
272272
273- let versions_and_publishers: Vec < ( Version , CrateName , Option < User > ) > = versions:: table
274- . filter ( versions:: id. eq_any ( version_ids) )
275- . inner_join ( crates:: table)
276- . left_outer_join ( users:: table)
277- . select ( <( Version , CrateName , Option < User > ) >:: as_select ( ) )
278- . load ( conn) ?;
279- let versions = versions_and_publishers
280- . iter ( )
281- . map ( |( v, ..) | v)
282- . collect :: < Vec < _ > > ( ) ;
283- let actions = VersionOwnerAction :: for_versions ( conn, & versions) ?;
284- let versions = versions_and_publishers
285- . into_iter ( )
286- . zip ( actions)
287- . map ( |( ( version, krate_name, published_by) , actions) | {
288- EncodableVersion :: from ( version, & krate_name. name , published_by, actions)
289- } )
290- . collect :: < Vec < _ > > ( ) ;
273+ let version_ids: Vec < i32 > = rev_deps. iter ( ) . map ( |dep| dep. version_id ) . collect ( ) ;
291274
292- Ok ( Json ( json ! ( {
293- "dependencies" : rev_deps,
294- "versions" : versions,
295- "meta" : { "total" : total } ,
296- } ) ) )
297- } )
298- . await
275+ let versions_and_publishers: Vec < ( Version , CrateName , Option < User > ) > = versions:: table
276+ . filter ( versions:: id. eq_any ( version_ids) )
277+ . inner_join ( crates:: table)
278+ . left_outer_join ( users:: table)
279+ . select ( <( Version , CrateName , Option < User > ) >:: as_select ( ) )
280+ . load ( & mut conn)
281+ . await ?;
282+
283+ let versions = versions_and_publishers
284+ . iter ( )
285+ . map ( |( v, ..) | v)
286+ . collect :: < Vec < _ > > ( ) ;
287+
288+ let actions = VersionOwnerAction :: async_for_versions ( & mut conn, & versions) . await ?;
289+
290+ let versions = versions_and_publishers
291+ . into_iter ( )
292+ . zip ( actions)
293+ . map ( |( ( version, krate_name, published_by) , actions) | {
294+ EncodableVersion :: from ( version, & krate_name. name , published_by, actions)
295+ } )
296+ . collect :: < Vec < _ > > ( ) ;
297+
298+ Ok ( Json ( json ! ( {
299+ "dependencies" : rev_deps,
300+ "versions" : versions,
301+ "meta" : { "total" : total } ,
302+ } ) ) )
299303}
0 commit comments