Skip to content

Newest updated #1931

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 17 commits into from
Dec 23, 2019
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
1 change: 1 addition & 0 deletions app/models/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default Model.extend({
created_at: attr('date'),
updated_at: attr('date'),
max_version: attr('string'),
newest_version: attr('string'),

description: attr('string'),
homepage: attr('string'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#each this.crates as |crate index|}}
<li>
<LinkTo @route="crate" @model={{crate.id}} class="name" data-test-crate-link={{index}}>
<span>{{ crate.name }} ({{ crate.max_version }})</span>
<span>{{ crate.name }}</span>
<div class='arrow-in-list'>
{{svg-jar "right-arrow"}}
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/templates/components/crate-list-newest.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ol>
{{#each this.crates as |crate index|}}
<li>
<LinkTo @route="crate.version" @models={{array crate.id crate.newest_version}} class="name" data-test-crate-link={{index}}>
<span>{{ crate.name }} ({{ crate.newest_version }})</span>
<div class='arrow-in-list'>
{{svg-jar "right-arrow"}}
</div>
</LinkTo>
</li>
{{/each}}
</ol>
8 changes: 4 additions & 4 deletions app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
<div id='home-crates' class='crate-lists'>
<section id='new-crates' data-test-new-crates aria-busy="{{this.dataTask.isRunning}}">
<h2>New Crates</h2>
<CrateList @crates={{this.model.new_crates}} />
<CrateListNewest @crates={{this.model.new_crates}} />
</section>
<section id='most-downloaded' data-test-most-downloaded aria-busy="{{this.dataTask.isRunning}}">
<h2>Most Downloaded</h2>
<CrateList @crates={{this.model.most_downloaded}} />
<CrateListNameOnly @crates={{this.model.most_downloaded}} />
</section>
<section id='just-updated' data-test-just-updated aria-busy="{{this.dataTask.isRunning}}">
<h2>Just Updated</h2>
<CrateList @crates={{this.model.just_updated}} />
<CrateListNewest @crates={{this.model.just_updated}} />
</section>
<section id='most-recently-downloaded' data-test-most-recently-downloaded aria-busy="{{this.dataTask.isRunning}}">
<h2>Most Recent Downloads</h2>
<CrateList @crates={{this.model.most_recently_downloaded}} />
<CrateListNameOnly @crates={{this.model.most_recently_downloaded}} />
</section>
<section id='keywords' data-test-keywords aria-busy="{{this.dataTask.isRunning}}">
<h2>Popular Keywords <LinkTo @route="keywords">(see all)</LinkTo></h2>
Expand Down
1 change: 1 addition & 0 deletions mirage/factories/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default Factory.extend({
homepage: () => faker.internet.url(),
repository: () => faker.internet.url(),
max_version: () => faker.system.semver(),
newest_version: () => faker.system.semver(),

created_at: () => faker.date.past(),
updated_at() {
Expand Down
19 changes: 19 additions & 0 deletions mirage/fixtures/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default [
id: 'kinetic-rust',
keywords: ['Protocol', 'Kinetic', 'Storage'],
max_version: '0.0.16',
newest_version: '0.0.16',
name: 'kinetic-rust',
repository: 'https://github.com/icorderi/kinetic-rust/',
updated_at: '2015-04-21T00:15:49Z',
Expand All @@ -41,6 +42,7 @@ export default [
id: 'nanomsg',
keywords: ['network'],
max_version: '0.7.0-alpha',
newest_version: '0.6.1',
name: 'nanomsg',
repository: 'https://github.com/thehydroimpulse/nanomsg.rs',
updated_at: '2016-12-28T08:40:00Z',
Expand Down Expand Up @@ -70,6 +72,7 @@ export default [
id: 'rust_mixin',
keywords: ['rust', 'plugin', 'code-generation'],
max_version: '0.0.1',
newest_version: '0.0.1',
name: 'rust_mixin',
repository: 'https://github.com/huonw/external_mixin',
updated_at: '2015-02-27T11:52:13Z',
Expand Down Expand Up @@ -142,6 +145,7 @@ export default [
id: 'external_mixin',
keywords: ['python', 'ruby', 'shell', 'plugin', 'code-generation'],
max_version: '0.0.1',
newest_version: '0.0.1',
name: 'external_mixin',
repository: 'https://github.com/huonw/external_mixin',
updated_at: '2015-02-27T11:51:58Z',
Expand All @@ -157,6 +161,7 @@ export default [
id: 'external_mixin_umbrella',
keywords: ['plugin', 'code-generation'],
max_version: '0.0.2',
newest_version: '0.0.2',
name: 'external_mixin_umbrella',
repository: 'https://github.com/huonw/external_mixin',
updated_at: '2015-02-27T11:52:30Z',
Expand All @@ -173,6 +178,7 @@ export default [
id: 'Inflector',
keywords: ['string', 'case', 'camel', 'snake', 'inflection'],
max_version: '0.1.6',
newest_version: '0.1.6',
name: 'Inflector',
repository: 'https://github.com/whatisinternet/inflector',
updated_at: '2015-10-27T01:51:42Z',
Expand All @@ -188,6 +194,7 @@ export default [
id: 'rs-es',
keywords: ['elasticsearch', 'elastic'],
max_version: '0.1.17',
newest_version: '0.1.17',
name: 'rs-es',
repository: 'https://github.com/benashford/rs-es',
updated_at: '2015-09-09T15:34:50Z',
Expand All @@ -203,6 +210,7 @@ export default [
id: 'rust-crypto',
keywords: ['Crypto', 'MD5', 'Sha1', 'Sha2', 'AES'],
max_version: '0.2.34',
newest_version: '0.2.34',
name: 'rust-crypto',
repository: 'https://github.com/DaGenix/rust-crypto/',
updated_at: '2015-10-29T01:16:17Z',
Expand All @@ -218,6 +226,7 @@ export default [
id: 'rust-htslib',
keywords: ['htslib', 'bam', 'bioinformatics', 'pileup', 'sequencing'],
max_version: '0.5.2',
newest_version: '0.5.2',
name: 'rust-htslib',
repository: 'https://github.com/rust-bio/rust-htslib.git',
updated_at: '2015-11-11T00:10:43Z',
Expand All @@ -233,6 +242,7 @@ export default [
id: 'rustless',
keywords: ['api', 'web', 'hyper', 'iron', 'rest'],
max_version: '0.8.0',
newest_version: '0.8.0',
name: 'rustless',
repository: 'https://crates.io/crates/rustless',
updated_at: '2015-10-31T11:49:29Z',
Expand All @@ -248,6 +258,7 @@ export default [
id: 'serde',
keywords: ['serde', 'serialization'],
max_version: '0.6.1',
newest_version: '0.6.1',
name: 'serde',
repository: 'https://github.com/serde-rs/serde',
updated_at: '2015-10-18T03:10:21Z',
Expand All @@ -263,6 +274,7 @@ export default [
id: 'rusted_cypher',
keywords: ['neo4j', 'database', 'query', 'cypher', 'graph'],
max_version: '0.7.1',
newest_version: '0.7.1',
name: 'rusted_cypher',
repository: 'https://github.com/livioribeiro/rusted-cypher',
updated_at: '2015-11-07T17:26:55Z',
Expand All @@ -279,6 +291,7 @@ export default [
id: 'zlib',
keywords: [],
max_version: '0.0.1',
newest_version: '0.0.1',
name: 'zlib',
repository: null,
updated_at: '2015-01-02T20:54:04Z',
Expand All @@ -295,6 +308,7 @@ export default [
id: 'rustful',
keywords: ['web', 'rest', 'framework', 'http', 'routing'],
max_version: '0.5.0',
newest_version: '0.5.0',
name: 'rustful',
repository: 'https://github.com/Ogeon/rustful',
updated_at: '2015-09-19T21:10:27Z',
Expand All @@ -310,6 +324,7 @@ export default [
id: 'postgres',
keywords: ['database', 'sql'],
max_version: '0.10.1',
newest_version: '0.10.1',
name: 'postgres',
repository: 'https://github.com/sfackler/rust-postgres',
updated_at: '2015-11-08T00:48:59Z',
Expand All @@ -325,6 +340,7 @@ export default [
id: 'quickcheck',
keywords: ['testing', 'quickcheck', 'property', 'shrinking', 'fuzz'],
max_version: '0.2.24',
newest_version: '0.2.24',
name: 'quickcheck',
repository: 'https://github.com/BurntSushi/quickcheck',
updated_at: '2015-09-20T21:53:38Z',
Expand All @@ -340,6 +356,7 @@ export default [
id: 'quickcheck_macros',
keywords: ['testing', 'quickcheck', 'property', 'shrinking', 'fuzz'],
max_version: '0.2.24',
newest_version: '0.2.24',
name: 'quickcheck_macros',
repository: 'https://github.com/BurntSushi/quickcheck',
updated_at: '2015-09-20T21:53:57Z',
Expand All @@ -356,6 +373,7 @@ export default [
id: 'nc_rustlex',
keywords: ['lexer', 'lexical', 'analyser', 'generator'],
max_version: '0.3.1',
newest_version: '0.3.1',
name: 'nc_rustlex',
repository: 'https://github.com/nicolas-cherel/rustlex',
updated_at: '2015-08-25T19:15:35Z',
Expand All @@ -371,6 +389,7 @@ export default [
id: 'nom',
keywords: ['parser', 'parser-combinators', 'parsing', 'streaming', 'bit'],
max_version: '1.0.1',
newest_version: '1.0.1',
name: 'nom',
repository: 'https://github.com/Geal/nom',
updated_at: '2015-11-22T22:00:41Z',
Expand Down
4 changes: 2 additions & 2 deletions mirage/fixtures/versions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export default [
{
crate: 'nanomsg',
created_at: '2016-12-27T08:40:00Z',
created_at: '2016-12-20T07:30:00Z',
dl_path: '/api/v1/crates/nanomsg/0.7.0-alpha.1/download',
downloads: 260,
features: {
bundled: ['nanomsg-sys/bundled'],
},
id: 40906,
num: '0.7.0-alpha.1',
updated_at: '2016-12-27T08:40:00Z',
updated_at: '2016-12-20T07:30:00Z',
yanked: false,
license: 'MIT',
crate_size: 912355,
Expand Down
1 change: 1 addition & 0 deletions mirage/serializers/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default BaseSerializer.extend({
'keywords',
'links',
'max_version',
'newest_version',
'name',
'repository',
'updated_at',
Expand Down
13 changes: 7 additions & 6 deletions src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Endpoints that expose metadata about a crate
//!
//! These endpoints provide data that could be obtained direclty from the
//! These endpoints provide data that could be obtained directly from the
//! index or cached metadata which was extracted (client side) from the
//! `Cargo.toml` file.

use crate::controllers::frontend_prelude::*;

use crate::models::{
Category, Crate, CrateCategory, CrateKeyword, CrateVersions, Keyword, RecentCrateDownloads,
User, Version, VersionOwnerAction,
Expand All @@ -31,10 +32,10 @@ pub fn summary(req: &mut dyn Request) -> AppResult<Response> {
versions
.grouped_by(&krates)
.into_iter()
.map(|versions| Version::max(versions.into_iter().map(|v| v.num)))
.map(|versions| Version::top(versions.into_iter().map(|v| (v.created_at, v.num))))
.zip(krates)
.map(|(max_version, krate)| {
Ok(krate.minimal_encodable(&max_version, None, false, None))
.map(|(top_versions, krate)| {
Ok(krate.minimal_encodable(&top_versions, None, false, None))
})
.collect()
};
Expand Down Expand Up @@ -142,7 +143,7 @@ pub fn show(req: &mut dyn Request) -> AppResult<Response> {
let badges = badges::table
.filter(badges::crate_id.eq(krate.id))
.load(&*conn)?;
let max_version = krate.max_version(&conn)?;
let top_versions = krate.top_versions(&conn)?;

#[derive(Serialize)]
struct R {
Expand All @@ -154,7 +155,7 @@ pub fn show(req: &mut dyn Request) -> AppResult<Response> {
}
Ok(req.json(&R {
krate: krate.clone().encodable(
&max_version,
&top_versions,
Some(ids),
Some(&kws),
Some(&cats),
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
// Update all badges for this crate, collecting any invalid badges in
// order to be able to warn about them
let ignored_invalid_badges = Badge::update_crate(&conn, &krate, new_crate.badges.as_ref())?;
let max_version = krate.max_version(&conn)?;
let top_versions = krate.top_versions(&conn)?;

if let Some(readme) = new_crate.readme {
render::render_and_upload_readme(
Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
};

Ok(req.json(&GoodCrate {
krate: krate.minimal_encodable(&max_version, None, false, None),
krate: krate.minimal_encodable(&top_versions, None, false, None),
warnings,
}))
})
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn search(req: &mut dyn Request) -> AppResult<Response> {
.load::<Version>(&*conn)?
.grouped_by(&crates)
.into_iter()
.map(|versions| Version::max(versions.into_iter().map(|v| v.num)));
.map(|versions| Version::top(versions.into_iter().map(|v| (v.created_at, v.num))));

let badges = CrateBadge::belonging_to(&crates)
.select((badges::crate_id, badges::all_columns))
Expand Down
31 changes: 16 additions & 15 deletions src/models/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use url::Url;

use crate::app::App;
use crate::email;
use crate::util::{cargo_err, AppResult};

use crate::models::version::TopVersions;
use crate::models::{
Badge, Category, CrateOwner, CrateOwnerInvitation, Keyword, NewCrateOwnerInvitation, Owner,
OwnerKind, ReverseDependency, User, Version,
};
use crate::util::{cargo_err, AppResult};
use crate::views::{EncodableCrate, EncodableCrateLinks};

use crate::models::helpers::with_count::*;
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<'a> NewCrate<'a> {
}

impl Crate {
/// SQL filter based on whether the crate's name loosly matches the given
/// SQL filter based on whether the crate's name loosely matches the given
/// string.
///
/// The operator used varies based on the input.
Expand Down Expand Up @@ -281,13 +281,13 @@ impl Crate {

pub fn minimal_encodable(
self,
max_version: &semver::Version,
top_versions: &TopVersions,
badges: Option<Vec<Badge>>,
exact_match: bool,
recent_downloads: Option<i64>,
) -> EncodableCrate {
self.encodable(
max_version,
top_versions,
None,
None,
None,
Expand All @@ -300,7 +300,7 @@ impl Crate {
#[allow(clippy::too_many_arguments)]
pub fn encodable(
self,
max_version: &semver::Version,
top_versions: &TopVersions,
versions: Option<Vec<i32>>,
keywords: Option<&[Keyword]>,
categories: Option<&[Category]>,
Expand Down Expand Up @@ -339,7 +339,8 @@ impl Crate {
keywords: keyword_ids,
categories: category_ids,
badges,
max_version: max_version.to_string(),
max_version: top_versions.highest.to_string(),
newest_version: top_versions.newest.to_string(),
documentation,
homepage,
exact_match,
Expand Down Expand Up @@ -384,16 +385,16 @@ impl Crate {
}
}

pub fn max_version(&self, conn: &PgConnection) -> AppResult<semver::Version> {
/// Return both the newest (most recently updated) and
/// highest version (in semver order) for the current crate.
pub fn top_versions(&self, conn: &PgConnection) -> AppResult<TopVersions> {
use crate::schema::versions::dsl::*;

let vs = self
.versions()
.select(num)
.load::<String>(conn)?
.into_iter()
.map(|s| semver::Version::parse(&s).unwrap());
Ok(Version::max(vs))
Ok(Version::top(
self.versions()
.select((updated_at, num))
.load::<(NaiveDateTime, semver::Version)>(conn)?,
))
}

pub fn owners(&self, conn: &PgConnection) -> AppResult<Vec<Owner>> {
Expand Down
Loading