|
7 | 7 | use crate::app::AppState; |
8 | 8 | use crate::controllers::krate::CratePath; |
9 | 9 | use crate::models::{ |
10 | | - Category, Crate, CrateCategory, CrateKeyword, Keyword, RecentCrateDownloads, TopVersions, User, |
11 | | - Version, VersionOwnerAction, |
| 10 | + Category, Crate, CrateCategory, CrateKeyword, Keyword, TopVersions, User, Version, |
| 11 | + VersionOwnerAction, |
12 | 12 | }; |
13 | 13 | use crate::schema::*; |
14 | 14 | use crate::util::errors::{ |
@@ -136,7 +136,7 @@ pub async fn find_crate( |
136 | 136 | ), |
137 | 137 | load_keywords(&mut conn, &krate, include.keywords), |
138 | 138 | load_categories(&mut conn, &krate, include.categories), |
139 | | - load_recent_downloads(&mut conn, &krate, include.downloads), |
| 139 | + load_recent_downloads(&mut conn, krate.id, include.downloads), |
140 | 140 | )?; |
141 | 141 |
|
142 | 142 | let ids = versions_and_publishers |
@@ -285,16 +285,17 @@ fn load_categories<'a>( |
285 | 285 | async move { Ok(Some(fut.await?)) }.boxed() |
286 | 286 | } |
287 | 287 |
|
288 | | -fn load_recent_downloads<'a>( |
| 288 | +fn load_recent_downloads( |
289 | 289 | conn: &mut AsyncPgConnection, |
290 | | - krate: &'a Crate, |
| 290 | + crate_id: i32, |
291 | 291 | includes: bool, |
292 | | -) -> BoxFuture<'a, AppResult<Option<i64>>> { |
| 292 | +) -> BoxFuture<'_, AppResult<Option<i64>>> { |
293 | 293 | if !includes { |
294 | 294 | return always_ready(|| Ok(None)).boxed(); |
295 | 295 | } |
296 | 296 |
|
297 | | - let fut = RecentCrateDownloads::belonging_to(&krate) |
| 297 | + let fut = recent_crate_downloads::table |
| 298 | + .filter(recent_crate_downloads::crate_id.eq(crate_id)) |
298 | 299 | .select(recent_crate_downloads::downloads) |
299 | 300 | .get_result(conn); |
300 | 301 | async move { Ok(fut.await.optional()?) }.boxed() |
|
0 commit comments