Skip to content

Expose the yanked field on the API #9817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 4, 2024
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
32 changes: 19 additions & 13 deletions src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,24 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
.transpose()?
.unwrap_or_default();

let (krate, downloads, default_version): (Crate, i64, Option<String>) =
Crate::by_name(&name)
.inner_join(crate_downloads::table)
.left_join(default_versions::table)
.left_join(versions::table.on(default_versions::version_id.eq(versions::id)))
.select((
Crate::as_select(),
crate_downloads::downloads,
versions::num.nullable(),
))
.first(conn)
.optional()?
.ok_or_else(|| crate_not_found(&name))?;
let (krate, downloads, default_version, yanked): (
Crate,
i64,
Option<String>,
Option<bool>,
) = Crate::by_name(&name)
.inner_join(crate_downloads::table)
.left_join(default_versions::table)
.left_join(versions::table.on(default_versions::version_id.eq(versions::id)))
.select((
Crate::as_select(),
crate_downloads::downloads,
versions::num.nullable(),
versions::yanked.nullable(),
))
.first(conn)
.optional()?
.ok_or_else(|| crate_not_found(&name))?;

let versions_publishers_and_audit_actions = if include.versions {
let mut versions_and_publishers: Vec<(Version, Option<User>)> = krate
Expand Down Expand Up @@ -126,6 +131,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
let encodable_crate = EncodableCrate::from(
krate.clone(),
default_version.as_deref(),
yanked,
top_versions.as_ref(),
ids,
kws.as_deref(),
Expand Down
1 change: 1 addition & 0 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
krate: EncodableCrate::from_minimal(
krate,
default_version.or(Some(version_string)).as_deref(),
Some(false),
Some(&top_versions),
false,
downloads,
Expand Down
21 changes: 18 additions & 3 deletions src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
recent_crate_downloads::downloads.nullable(),
0_f32.into_sql::<Float>(),
versions::num.nullable(),
versions::yanked.nullable(),
);

let mut seek: Option<Seek> = None;
Expand Down Expand Up @@ -117,6 +118,7 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
recent_crate_downloads::downloads.nullable(),
rank.clone(),
versions::num.nullable(),
versions::yanked.nullable(),
));
seek = Some(Seek::Relevance);
query = query.then_order_by(rank.desc())
Expand All @@ -128,6 +130,7 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
recent_crate_downloads::downloads.nullable(),
0_f32.into_sql::<Float>(),
versions::num.nullable(),
versions::yanked.nullable(),
));
seek = Some(Seek::Query);
}
Expand Down Expand Up @@ -231,10 +234,14 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
let crates = versions
.zip(data)
.map(
|(max_version, (krate, perfect_match, total, recent, _, default_version))| {
|(
max_version,
(krate, perfect_match, total, recent, _, default_version, yanked),
)| {
EncodableCrate::from_minimal(
krate,
default_version.as_deref(),
yanked,
Some(&max_version),
perfect_match,
total,
Expand Down Expand Up @@ -621,7 +628,7 @@ mod seek {
downloads,
recent_downloads,
rank,
_,
..,
) = *record;

match *self {
Expand All @@ -644,7 +651,15 @@ mod seek {
}
}

type Record = (Crate, bool, i64, Option<i64>, f32, Option<String>);
type Record = (
Crate,
bool,
i64,
Option<i64>,
f32,
Option<String>,
Option<bool>,
);

type QuerySource = LeftJoinQuerySource<
LeftJoinQuerySource<
Expand Down
28 changes: 17 additions & 11 deletions src/controllers/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {

fn encode_crates(
conn: &mut impl Conn,
data: Vec<(Crate, i64, Option<i64>, Option<String>)>,
data: Vec<Record>,
) -> AppResult<Vec<EncodableCrate>> {
let krates = data.iter().map(|(c, ..)| c).collect::<Vec<_>>();
let versions: Vec<Version> = krates.versions().load(conn)?;
Expand All @@ -43,16 +43,19 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
.into_iter()
.map(TopVersions::from_versions)
.zip(data)
.map(|(top_versions, (krate, total, recent, default_version))| {
Ok(EncodableCrate::from_minimal(
krate,
default_version.as_deref(),
Some(&top_versions),
false,
total,
recent,
))
})
.map(
|(top_versions, (krate, total, recent, default_version, yanked))| {
Ok(EncodableCrate::from_minimal(
krate,
default_version.as_deref(),
yanked,
Some(&top_versions),
false,
total,
recent,
))
},
)
.collect()
}

Expand All @@ -61,6 +64,7 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
crate_downloads::downloads,
recent_crate_downloads::downloads.nullable(),
versions::num.nullable(),
versions::yanked.nullable(),
);

let new_crates = crates::table
Expand Down Expand Up @@ -136,3 +140,5 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
})
.await
}

type Record = (Crate, i64, Option<i64>, Option<String>, Option<bool>);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ expression: response.json()
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
"versions": null,
"yanked": false
},
"warnings": {
"invalid_badges": [],
Expand Down
Loading