Skip to content

Commit db076e9

Browse files
author
Christopher Brookes
authored
perf: asynchronously fetch classes counts in sidebar to not block dashboard (#1802)
1 parent 689df7c commit db076e9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Add multi-factor authentication to dashboard login. To use one-time password, run `parse-dashboard --createMFA` or `parse-dashboard --createUser`. (Daniel Blyth) [#1624](https://github.com/parse-community/parse-dashboard/pull/1624)
88

99
## Improvements
10+
- Sidebar: Class counts are now updated when all counts are returned instead of after each call (Christopher Brookes) [#1802](https://github.com/parse-community/parse-dashboard/pull/1802)
1011
- Update sass to 5.0.0 and make docker image use node:lts-alpine (Corey Baker) [#1792](https://github.com/parse-community/parse-dashboard/pull/1792)
1112
- Docker image use now node 12 version (Christopher Brookes) [#1788](https://github.com/parse-community/parse-dashboard/pull/1788)
1213
- CI now pushes docker images to Docker Hub (Corey Baker) [#1781](https://github.com/parse-community/parse-dashboard/pull/1781)

src/dashboard/Data/Browser/Browser.react.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Browser extends DashboardView {
6464

6565
relation: null,
6666
counts: {},
67+
computingClassCounts: false,
6768
filteredCounts: {},
6869
clp: {},
6970
filters: new List(),
@@ -605,12 +606,21 @@ class Browser extends DashboardView {
605606
});
606607
}
607608

608-
handleFetchedSchema() {
609-
this.props.schema.data.get('classes').forEach((_, className) => {
610-
this.context.currentApp.getClassCount(className)
611-
.then(count => this.setState({ counts: { [className]: count, ...this.state.counts } }));
612-
})
613-
this.setState({clp: this.props.schema.data.get('CLPs').toJS()});
609+
async handleFetchedSchema() {
610+
const counts = this.state.counts;
611+
if (this.state.computingClassCounts === false) {
612+
this.setState({ computingClassCounts: true });
613+
for (const parseClass of this.props.schema.data.get('classes')) {
614+
const [className] = parseClass;
615+
counts[className] = await this.context.currentApp.getClassCount(className);
616+
}
617+
618+
this.setState({
619+
clp: this.props.schema.data.get('CLPs').toJS(),
620+
counts,
621+
computingClassCounts: false
622+
});
623+
}
614624
}
615625

616626
async refresh() {

0 commit comments

Comments
 (0)