Skip to content

Commit 5c088d8

Browse files
authored
Merge pull request #11624 from Turbo87/rcd
Remove `RecentCrateDownloads` struct
2 parents 2c69582 + f3dde1c commit 5c088d8

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

crates/crates_io_database/src/models/krate.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ use tracing::instrument;
1818

1919
use super::Team;
2020

21-
#[derive(Debug, Queryable, Identifiable, Associations, Clone, Copy)]
22-
#[diesel(
23-
table_name = recent_crate_downloads,
24-
check_for_backend(diesel::pg::Pg),
25-
primary_key(crate_id),
26-
belongs_to(Crate),
27-
)]
28-
pub struct RecentCrateDownloads {
29-
pub crate_id: i32,
30-
pub downloads: i32,
31-
}
32-
3321
#[derive(Debug, Clone, Queryable, Selectable)]
3422
#[diesel(table_name = crates, check_for_backend(diesel::pg::Pg))]
3523
pub struct CrateName {

crates/crates_io_database/src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::download::VersionDownload;
1010
pub use self::email::{Email, NewEmail};
1111
pub use self::follow::Follow;
1212
pub use self::keyword::{CrateKeyword, Keyword};
13-
pub use self::krate::{Crate, CrateName, NewCrate, RecentCrateDownloads};
13+
pub use self::krate::{Crate, CrateName, NewCrate};
1414
pub use self::owner::{CrateOwner, Owner, OwnerKind};
1515
pub use self::team::{NewTeam, Team};
1616
pub use self::token::ApiToken;

src/controllers/krate/metadata.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use crate::app::AppState;
88
use crate::controllers::krate::CratePath;
99
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,
1212
};
1313
use crate::schema::*;
1414
use crate::util::errors::{
@@ -136,7 +136,7 @@ pub async fn find_crate(
136136
),
137137
load_keywords(&mut conn, &krate, include.keywords),
138138
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),
140140
)?;
141141

142142
let ids = versions_and_publishers
@@ -285,16 +285,17 @@ fn load_categories<'a>(
285285
async move { Ok(Some(fut.await?)) }.boxed()
286286
}
287287

288-
fn load_recent_downloads<'a>(
288+
fn load_recent_downloads(
289289
conn: &mut AsyncPgConnection,
290-
krate: &'a Crate,
290+
crate_id: i32,
291291
includes: bool,
292-
) -> BoxFuture<'a, AppResult<Option<i64>>> {
292+
) -> BoxFuture<'_, AppResult<Option<i64>>> {
293293
if !includes {
294294
return always_ready(|| Ok(None)).boxed();
295295
}
296296

297-
let fut = RecentCrateDownloads::belonging_to(&krate)
297+
let fut = recent_crate_downloads::table
298+
.filter(recent_crate_downloads::crate_id.eq(crate_id))
298299
.select(recent_crate_downloads::downloads)
299300
.get_result(conn);
300301
async move { Ok(fut.await.optional()?) }.boxed()

0 commit comments

Comments
 (0)