Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions crates/crates_io_database/src/models/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ use tracing::instrument;

use super::Team;

#[derive(Debug, Queryable, Identifiable, Associations, Clone, Copy)]
#[diesel(
table_name = recent_crate_downloads,
check_for_backend(diesel::pg::Pg),
primary_key(crate_id),
belongs_to(Crate),
)]
pub struct RecentCrateDownloads {
pub crate_id: i32,
pub downloads: i32,
}

#[derive(Debug, Clone, Queryable, Selectable)]
#[diesel(table_name = crates, check_for_backend(diesel::pg::Pg))]
pub struct CrateName {
Expand Down
2 changes: 1 addition & 1 deletion crates/crates_io_database/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use self::download::VersionDownload;
pub use self::email::{Email, NewEmail};
pub use self::follow::Follow;
pub use self::keyword::{CrateKeyword, Keyword};
pub use self::krate::{Crate, CrateName, NewCrate, RecentCrateDownloads};
pub use self::krate::{Crate, CrateName, NewCrate};
pub use self::owner::{CrateOwner, Owner, OwnerKind};
pub use self::team::{NewTeam, Team};
pub use self::token::ApiToken;
Expand Down
15 changes: 8 additions & 7 deletions src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use crate::app::AppState;
use crate::controllers::krate::CratePath;
use crate::models::{
Category, Crate, CrateCategory, CrateKeyword, Keyword, RecentCrateDownloads, TopVersions, User,
Version, VersionOwnerAction,
Category, Crate, CrateCategory, CrateKeyword, Keyword, TopVersions, User, Version,
VersionOwnerAction,
};
use crate::schema::*;
use crate::util::errors::{
Expand Down Expand Up @@ -136,7 +136,7 @@ pub async fn find_crate(
),
load_keywords(&mut conn, &krate, include.keywords),
load_categories(&mut conn, &krate, include.categories),
load_recent_downloads(&mut conn, &krate, include.downloads),
load_recent_downloads(&mut conn, krate.id, include.downloads),
)?;

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

fn load_recent_downloads<'a>(
fn load_recent_downloads(
conn: &mut AsyncPgConnection,
krate: &'a Crate,
crate_id: i32,
includes: bool,
) -> BoxFuture<'a, AppResult<Option<i64>>> {
) -> BoxFuture<'_, AppResult<Option<i64>>> {
if !includes {
return always_ready(|| Ok(None)).boxed();
}

let fut = RecentCrateDownloads::belonging_to(&krate)
let fut = recent_crate_downloads::table
.filter(recent_crate_downloads::crate_id.eq(crate_id))
.select(recent_crate_downloads::downloads)
.get_result(conn);
async move { Ok(fut.await.optional()?) }.boxed()
Expand Down