Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1354: Don't use shields.io's crate badges r=sgrif

Every single time someone loads a crates.io badge from shields.io, they
make a separate API call to our servers for each one, with no caching.
This means that right now when you go to the search page, you're going
to make 11 API calls when you should be making 1. The result is that shields.io
accounts for an unreasonably large amount of traffic to our systems.

We have all the information we need for this badge when we load the page,
so let's just do that and use their "badge with these words" API instead.

I've just removed it from the version show page since we already display
that info elsewhere on the page, and it's especially confusing when the
numbers don't match.
  • Loading branch information
bors-voyager[bot] committed Apr 14, 2018
2 parents dbbefe1 + 95ddb16 commit 78b408b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
16 changes: 16 additions & 0 deletions app/components/crate-badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Component from '@ember/component';
import { computed } from '@ember/object';

export default Component.extend({
classNames: ['vers'],

tagName: 'span',

color: computed('crate.max_version', function() {
if (this.get('crate.max_version')[0] == '0') {
return 'orange';
} else {
return 'blue';
}
}),
});
5 changes: 5 additions & 0 deletions app/templates/components/crate-badge.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img
src="https://img.shields.io/badge/crates.io-v{{ crate.max_version }}-{{ color }}.svg?longCache=true"
alt="{{ crate.max_version }}"
title="{{ crate.name }}’s current version badge"
data-test-version-badge>
8 changes: 1 addition & 7 deletions app/templates/components/crate-row.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<div class='desc'>
<div class='info'>
{{#link-to 'crate' crate.id data-test-crate-link}}{{ crate.name }}{{/link-to}}
<span class='vers'>
<img
src="https://img.shields.io/crates/v/{{ crate.name }}.svg"
alt="{{ crate.max_version }}"
title="{{ crate.name }}’s current version badge"
data-test-version-badge>
</span>
{{crate-badge crate=crate}}
{{#each crate.annotated_badges as |badge|}}
{{component badge.component_name badge=badge data-test-badge=badge.badge_type}}
{{/each}}
Expand Down
7 changes: 0 additions & 7 deletions app/templates/crate/version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@
<div>
<div class='last-update'><span class='small'>Last Updated</span></div>
<div class='date'>{{moment-from-now crate.updated_at}}</div>
<p>
<img
src="https://img.shields.io/crates/v/{{ crate.name }}.svg"
alt="{{ crate.name }}’s current version badge"
title="{{ crate.name }}’s current version badge">
</p>

{{#each crate.annotated_badges as |badge|}}
<p>
{{component badge.component_name badge=badge}}
Expand Down

0 comments on commit 78b408b

Please sign in to comment.