Skip to content

Commit 20a5eb0

Browse files
committed
crate.version: Cache README per version
... instead of the broken per crate caching
1 parent 03f0cdf commit 20a5eb0

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

app/controllers/crate/version.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,24 @@ export default Controller.extend({
127127
return data;
128128
}),
129129

130+
readme: alias('loadReadmeTask.last.value'),
131+
130132
loadReadmeTask: task(function* () {
131-
try {
132-
this.crate.set('readme', yield this.currentVersion.loadReadmeTask.perform());
133-
134-
if (typeof document !== 'undefined') {
135-
setTimeout(() => {
136-
let e = document.createEvent('CustomEvent');
137-
e.initCustomEvent('hashchange', true, true);
138-
window.dispatchEvent(e);
139-
});
140-
}
141-
} catch (error) {
142-
this.crate.set('readme', null);
133+
let version = this.currentVersion;
134+
135+
let readme = version.loadReadmeTask.lastSuccessful
136+
? version.loadReadmeTask.lastSuccessful.value
137+
: yield version.loadReadmeTask.perform();
138+
139+
if (typeof document !== 'undefined') {
140+
setTimeout(() => {
141+
let e = document.createEvent('CustomEvent');
142+
e.initCustomEvent('hashchange', true, true);
143+
window.dispatchEvent(e);
144+
});
143145
}
146+
147+
return readme;
144148
}),
145149

146150
documentationLink: computed(

app/routes/crate/version.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export default Route.extend({
6262
this._super(...arguments);
6363

6464
model.version.loadDepsTask.perform();
65-
controller.loadReadmeTask.perform();
65+
controller.loadReadmeTask.perform().catch(() => {
66+
// ignored
67+
});
6668

6769
let { crate } = model;
6870
if (!crate.documentation || crate.documentation.startsWith('https://docs.rs/')) {

app/templates/crate/version.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
<CrateTomlCopy @copyText={{this.crateTomlText}} />
5757
{{/if}}
5858
</div>
59-
{{#if this.crate.readme}}
59+
{{#if this.readme}}
6060
<section local-class="crate-readme" aria-label="Readme" {{highlight-syntax selector="pre > code"}}>
61-
{{html-safe this.crate.readme}}
61+
{{html-safe this.readme}}
6262
</section>
6363
{{else}}
6464
{{#if this.crate.description}}

0 commit comments

Comments
 (0)