Skip to content

Commit fd8bb8b

Browse files
committed
Remove RecentCrateDownloads struct
We were only using it for the `belonging_to()` association, but we can easily achieve the same with a simple `filter()` call. Since each model struct is generating a considerate amount of code lets remove it until we actually need it.
1 parent 2c69582 commit fd8bb8b

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
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: 4 additions & 3 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::{
@@ -294,7 +294,8 @@ fn load_recent_downloads<'a>(
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(krate.id))
298299
.select(recent_crate_downloads::downloads)
299300
.get_result(conn);
300301
async move { Ok(fut.await.optional()?) }.boxed()

0 commit comments

Comments
 (0)