Skip to content

Commit a658181

Browse files
committed
Auto merge of #4130 - Turbo87:duplicate-playground-req, r=locks
services/playground: Extract loadCrates() method This avoids duplicate requests to the playground API, caused by the `preloadPlaygroundCratesTask` in the `application` route requesting the data after it has already been loaded by the `CrateSidebar` component too.
2 parents fd99c9d + d6b376c commit a658181

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

app/components/crate-sidebar.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ export default class DownloadGraph extends Component {
3636
super(...arguments);
3737

3838
// load Rust Playground crates list, if necessary
39-
if (!this.playground.crates) {
40-
this.playground.loadCratesTask.perform().catch(error => {
41-
if (!(didCancel(error) || error.isServerError || error.isNetworkError)) {
42-
// report unexpected errors to Sentry
43-
this.sentry.captureException(error);
44-
}
45-
});
46-
}
39+
this.playground.loadCrates().catch(error => {
40+
if (!(didCancel(error) || error.isServerError || error.isNetworkError)) {
41+
// report unexpected errors to Sentry
42+
this.sentry.captureException(error);
43+
}
44+
});
4745
}
4846
}

app/routes/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ export default class ApplicationRoute extends Route {
4747

4848
@task *preloadPlaygroundCratesTask() {
4949
yield rawTimeout(1000);
50-
yield this.playground.loadCratesTask.perform();
50+
yield this.playground.loadCrates();
5151
}
5252
}

app/services/playground.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import ajax from '../utils/ajax';
88
export default class PlaygroundService extends Service {
99
@alias('loadCratesTask.lastSuccessful.value') crates;
1010

11+
async loadCrates() {
12+
if (!this.crates) {
13+
return this.loadCratesTask.perform();
14+
}
15+
}
16+
1117
@dropTask *loadCratesTask() {
1218
let response = yield ajax('https://play.rust-lang.org/meta/crates');
1319
return response.crates;

0 commit comments

Comments
 (0)