@@ -25,7 +25,8 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
2525
2626 async fn inner (
2727 conn : & mut AsyncPgConnection ,
28- ) -> QueryResult < ( i64 , i64 , Vec < Record > , Vec < Record > ) > {
28+ config : & crate :: config:: Server ,
29+ ) -> QueryResult < ( i64 , i64 , Vec < Record > , Vec < Record > , Vec < Record > , Vec < Record > ) > {
2930 use diesel:: {
3031 ExpressionMethods , JoinOnDsl , NullableExpressionMethods , QueryDsl , SelectableHelper ,
3132 } ;
@@ -67,17 +68,64 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
6768 . load ( conn)
6869 . await ?;
6970
70- Ok ( ( num_crates, num_downloads, new_crates, just_updated) )
71+ let mut most_downloaded_query = crates:: table
72+ . inner_join ( crate_downloads:: table)
73+ . left_join ( recent_crate_downloads:: table)
74+ . left_join ( default_versions:: table)
75+ . left_join ( versions:: table. on ( default_versions:: version_id. eq ( versions:: id) ) )
76+ . into_boxed ( ) ;
77+ if !config. excluded_crate_names . is_empty ( ) {
78+ most_downloaded_query =
79+ most_downloaded_query. filter ( crates:: name. ne_all ( & config. excluded_crate_names ) ) ;
80+ }
81+ let most_downloaded = most_downloaded_query
82+ . then_order_by ( crate_downloads:: downloads. desc ( ) )
83+ . select ( selection)
84+ . limit ( 10 )
85+ . load ( conn)
86+ . await ?;
87+
88+ let mut most_recently_downloaded_query = crates:: table
89+ . inner_join ( crate_downloads:: table)
90+ . inner_join ( recent_crate_downloads:: table)
91+ . left_join ( default_versions:: table)
92+ . left_join ( versions:: table. on ( default_versions:: version_id. eq ( versions:: id) ) )
93+ . into_boxed ( ) ;
94+ if !config. excluded_crate_names . is_empty ( ) {
95+ most_recently_downloaded_query = most_recently_downloaded_query
96+ . filter ( crates:: name. ne_all ( & config. excluded_crate_names ) ) ;
97+ }
98+ let most_recently_downloaded = most_recently_downloaded_query
99+ . then_order_by ( recent_crate_downloads:: downloads. desc ( ) )
100+ . select ( selection)
101+ . limit ( 10 )
102+ . load ( conn)
103+ . await ?;
104+
105+ Ok ( (
106+ num_crates,
107+ num_downloads,
108+ new_crates,
109+ just_updated,
110+ most_downloaded,
111+ most_recently_downloaded,
112+ ) )
71113 }
72114
73- let ( num_crates, num_downloads, new_crates, just_updated) = inner ( & mut conn) . await ?;
115+ let config = & state. config ;
116+ let (
117+ num_crates,
118+ num_downloads,
119+ new_crates,
120+ just_updated,
121+ most_downloaded,
122+ most_recently_downloaded,
123+ ) = inner ( & mut conn, config) . await ?;
74124
75125 spawn_blocking ( move || {
76126 use diesel:: prelude:: * ;
77127 let conn: & mut AsyncConnectionWrapper < _ > = & mut conn. into ( ) ;
78128
79- let config = & state. config ;
80-
81129 fn encode_crates (
82130 conn : & mut impl Conn ,
83131 data : Vec < Record > ,
@@ -105,46 +153,6 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
105153 . collect ( )
106154 }
107155
108- let selection = (
109- Crate :: as_select ( ) ,
110- crate_downloads:: downloads,
111- recent_crate_downloads:: downloads. nullable ( ) ,
112- versions:: num. nullable ( ) ,
113- versions:: yanked. nullable ( ) ,
114- ) ;
115-
116- let mut most_downloaded_query = crates:: table
117- . inner_join ( crate_downloads:: table)
118- . left_join ( recent_crate_downloads:: table)
119- . left_join ( default_versions:: table)
120- . left_join ( versions:: table. on ( default_versions:: version_id. eq ( versions:: id) ) )
121- . into_boxed ( ) ;
122- if !config. excluded_crate_names . is_empty ( ) {
123- most_downloaded_query =
124- most_downloaded_query. filter ( crates:: name. ne_all ( & config. excluded_crate_names ) ) ;
125- }
126- let most_downloaded = most_downloaded_query
127- . then_order_by ( crate_downloads:: downloads. desc ( ) )
128- . select ( selection)
129- . limit ( 10 )
130- . load ( conn) ?;
131-
132- let mut most_recently_downloaded_query = crates:: table
133- . inner_join ( crate_downloads:: table)
134- . inner_join ( recent_crate_downloads:: table)
135- . left_join ( default_versions:: table)
136- . left_join ( versions:: table. on ( default_versions:: version_id. eq ( versions:: id) ) )
137- . into_boxed ( ) ;
138- if !config. excluded_crate_names . is_empty ( ) {
139- most_recently_downloaded_query = most_recently_downloaded_query
140- . filter ( crates:: name. ne_all ( & config. excluded_crate_names ) ) ;
141- }
142- let most_recently_downloaded = most_recently_downloaded_query
143- . then_order_by ( recent_crate_downloads:: downloads. desc ( ) )
144- . select ( selection)
145- . limit ( 10 )
146- . load ( conn) ?;
147-
148156 let popular_keywords = keywords:: table
149157 . order ( keywords:: crates_cnt. desc ( ) )
150158 . limit ( 10 )
0 commit comments