Skip to content

Commit

Permalink
controllers/krate/metadata: Constructing TopVersions from fetched v…
Browse files Browse the repository at this point in the history
…ersions
  • Loading branch information
eth3lbert committed Dec 31, 2024
1 parent 76f49fe commit 622eef5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 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, User, Version,
VersionOwnerAction,
Category, Crate, CrateCategory, CrateKeyword, Keyword, RecentCrateDownloads, TopVersions, User,
Version, VersionOwnerAction,
};
use crate::schema::*;
use crate::util::errors::{bad_request, crate_not_found, AppResult, BoxedAppError};
Expand Down Expand Up @@ -146,8 +146,16 @@ pub async fn find_crate(
None
};

let top_versions = if include.versions {
Some(krate.top_versions(&mut conn).await?)
let top_versions = if let Some(versions) = versions_publishers_and_audit_actions
.as_ref()
.filter(|_| include.versions)
{
let pairs = versions
.iter()
.filter(|(v, _, _)| !v.yanked)
.cloned()
.map(|(v, _, _)| (v.created_at, v.num));
Some(TopVersions::from_date_version_pairs(pairs))
} else {
None
};
Expand Down

0 comments on commit 622eef5

Please sign in to comment.