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
2 changes: 1 addition & 1 deletion app/components/crate-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</nav.Tab>

<nav.Tab @link={{link "crate.versions" @crate}} data-test-versions-tab>
{{pluralize @crate.versions.length "Version"}}
{{pluralize @crate.num_versions "Version"}}
</nav.Tab>

<nav.Tab
Expand Down
1 change: 1 addition & 0 deletions app/models/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Crate extends Model {
* @type {string | null}
*/
@attr default_version;
@attr num_versions;
@attr yanked;
@attr max_version;
@attr max_stable_version;
Expand Down
2 changes: 1 addition & 1 deletion app/templates/crate/versions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div local-class="results-meta">
<span local-class="page-description" data-test-page-description>
All <strong>{{ this.model.versions.length }}</strong>
All <strong>{{ this.model.num_versions }}</strong>
versions of <strong>{{ this.model.name }}</strong> since
{{date-format this.model.created_at 'PPP'}}
</span>
Expand Down
2 changes: 2 additions & 0 deletions packages/crates-io-msw/handlers/crates/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test('returns a crate object for known crates', async function () {
max_stable_version: null,
name: 'rand',
newest_version: '1.0.0-beta.1',
num_versions: 1,
repository: null,
recent_downloads: 321,
updated_at: '2017-02-24T12:34:56Z',
Expand Down Expand Up @@ -101,6 +102,7 @@ test('works for non-canonical names', async function () {
max_stable_version: null,
name: 'foo-bar',
newest_version: '1.0.0-beta.1',
num_versions: 1,
repository: null,
recent_downloads: 321,
updated_at: '2017-02-24T12:34:56Z',
Expand Down
1 change: 1 addition & 0 deletions packages/crates-io-msw/handlers/crates/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test('returns a paginated crates list', async function () {
max_stable_version: '1.0.0',
name: 'rand',
newest_version: '2.0.0-beta.1',
num_versions: 2,
repository: null,
recent_downloads: 321,
updated_at: '2017-02-24T12:34:56Z',
Expand Down
4 changes: 4 additions & 0 deletions packages/crates-io-msw/handlers/summary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test('returns the data for the front page', async function () {
max_stable_version: '1.0.0',
name: 'crate-1',
newest_version: '1.0.0',
num_versions: 1,
recent_downloads: 321,
repository: null,
updated_at: '2017-02-24T12:34:56Z',
Expand Down Expand Up @@ -81,6 +82,7 @@ test('returns the data for the front page', async function () {
max_stable_version: '1.0.3',
name: 'crate-4',
newest_version: '1.0.3',
num_versions: 1,
repository: null,
recent_downloads: 963,
updated_at: '2017-02-24T12:34:56Z',
Expand Down Expand Up @@ -111,6 +113,7 @@ test('returns the data for the front page', async function () {
max_stable_version: '1.0.10',
name: 'crate-11',
newest_version: '1.0.10',
num_versions: 1,
repository: null,
recent_downloads: 3852,
updated_at: '2017-02-24T12:34:56Z',
Expand Down Expand Up @@ -141,6 +144,7 @@ test('returns the data for the front page', async function () {
max_stable_version: '1.0.19',
name: 'crate-20',
newest_version: '1.0.19',
num_versions: 1,
repository: null,
recent_downloads: 1605,
updated_at: '2017-02-24T12:34:56Z',
Expand Down
2 changes: 2 additions & 0 deletions packages/crates-io-msw/serializers/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function serializeCrate(
versionNums.find(it => !versionsByNum[it].yanked) ??
versionNums[0];

serialized.num_versions = versions.length;

serialized.yanked = versionsByNum[serialized.default_version]?.yanked ?? false;

serialized.links = {
Expand Down
37 changes: 22 additions & 15 deletions src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,27 @@ pub async fn find_crate(
.transpose()?
.unwrap_or_default();

let (krate, downloads, default_version, yanked): (Crate, i64, Option<String>, Option<bool>) =
Crate::by_name(&path.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(&mut conn)
.await
.optional()?
.ok_or_else(|| crate_not_found(&path.name))?;
let (krate, downloads, default_version, yanked, num_versions): (
Crate,
i64,
Option<String>,
Option<bool>,
Option<i32>,
) = Crate::by_name(&path.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(),
default_versions::num_versions.nullable(),
))
.first(&mut conn)
.await
.optional()?
.ok_or_else(|| crate_not_found(&path.name))?;

let mut versions_publishers_and_audit_actions = if include.versions {
let versions_and_publishers: Vec<(Version, Option<User>)> = Version::belonging_to(&krate)
Expand Down Expand Up @@ -183,6 +189,7 @@ pub async fn find_crate(
let encodable_crate = EncodableCrate::from(
krate.clone(),
default_version.as_deref(),
num_versions.unwrap_or_default(),
yanked,
top_versions.as_ref(),
ids,
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,12 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
let existing_default_version = default_versions::table
.inner_join(versions::table)
.filter(default_versions::crate_id.eq(krate.id))
.select(DefaultVersion::as_select())
.first(conn)
.select((DefaultVersion::as_select(), default_versions::num_versions))
.first::<(DefaultVersion, Option<i32>)>(conn)
.await
.optional()?;

let num_versions = existing_default_version.as_ref().and_then(|t|t.1).unwrap_or_default();
let mut default_version = None;
// Upsert the `default_value` determined by the existing `default_value` and the
// published version. Note that this could potentially write an outdated version
Expand All @@ -450,7 +451,7 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
// Compared to only using a background job, this prevents us from getting into a
// situation where a crate exists in the `crates` table but doesn't have a default
// version in the `default_versions` table.
if let Some(existing_default_version) = existing_default_version {
if let Some((existing_default_version, _)) = existing_default_version {
let published_default_version = DefaultVersion {
id: version.id,
num: semver,
Expand Down Expand Up @@ -562,6 +563,7 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
krate: EncodableCrate::from_minimal(
krate,
default_version.or(Some(version_string)).as_deref(),
num_versions,
Some(false),
Some(&top_versions),
false,
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub async fn list_crates(
0_f32.into_sql::<Float>(),
versions::num.nullable(),
versions::yanked.nullable(),
default_versions::num_versions.nullable(),
);

let mut seek: Option<Seek> = None;
Expand Down Expand Up @@ -113,6 +114,7 @@ pub async fn list_crates(
rank,
versions::num.nullable(),
versions::yanked.nullable(),
default_versions::num_versions.nullable(),
));
seek = Some(Seek::Relevance);
query = query.then_order_by(rank.desc())
Expand All @@ -125,6 +127,7 @@ pub async fn list_crates(
0_f32.into_sql::<Float>(),
versions::num.nullable(),
versions::yanked.nullable(),
default_versions::num_versions.nullable(),
));
seek = Some(Seek::Query);
}
Expand Down Expand Up @@ -227,6 +230,7 @@ pub async fn list_crates(
EncodableCrate::from_minimal(
record.krate,
record.default_version.as_deref(),
record.num_versions.unwrap_or_default(),
record.yanked,
Some(&max_version),
record.exact_match,
Expand Down Expand Up @@ -704,6 +708,7 @@ struct Record {
rank: f32,
default_version: Option<String>,
yanked: Option<bool>,
num_versions: Option<i32>,
}

type QuerySource = LeftJoinQuerySource<
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ struct Record {
default_version: Option<String>,
#[diesel(select_expression = versions::columns::yanked.nullable())]
yanked: Option<bool>,
#[diesel(select_expression = default_versions::columns::num_versions.nullable())]
num_versions: Option<i32>,
}

fn encode_crates(
Expand Down Expand Up @@ -165,6 +167,7 @@ fn encode_crates(
Ok(EncodableCrate::from_minimal(
record.krate,
record.default_version.as_deref(),
record.num_versions.unwrap_or_default(),
record.yanked,
Some(&top_versions),
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_new",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "2.0.0",
"name": "foo_twice",
"newest_version": "2.0.0",
"num_versions": 2,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "2.0.0",
"name": "foo_twice",
"newest_version": "0.99.0",
"num_versions": 2,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "0.0.0-pre",
"name": "foo_weird",
"newest_version": "0.0.0-pre",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_new",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0+foo",
"name": "foo",
"newest_version": "1.0.0+foo",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0-beta.1",
"name": "foo",
"newest_version": "1.0.0-beta.1",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0+foo",
"name": "foo",
"newest_version": "1.0.0+foo",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_good_cat",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_good_key",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.1.0",
"name": "foo",
"newest_version": "1.1.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_readme",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0",
"name": "foo_readme",
"newest_version": "1.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ expression: response.json()
"max_version": "1.0.0+foo",
"name": "foo_readme",
"newest_version": "1.0.0+foo",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ expression: response.json()
"max_version": "0.0.0",
"name": "foo_default_version",
"newest_version": "0.0.0",
"num_versions": 3,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ expression: response.json()
"max_version": "0.0.0",
"name": "new",
"newest_version": "0.0.0",
"num_versions": 1,
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
Expand Down
Loading
Loading