Skip to content
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

perf: asynchronously fetch classes counts in sidebar to not block dashboard #1802

Merged
merged 1 commit into from
Sep 19, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- 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)

## Improvements
- 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)
- 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)
- Docker image use now node 12 version (Christopher Brookes) [#1788](https://github.com/parse-community/parse-dashboard/pull/1788)
- CI now pushes docker images to Docker Hub (Corey Baker) [#1781](https://github.com/parse-community/parse-dashboard/pull/1781)
Expand Down
22 changes: 16 additions & 6 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Browser extends DashboardView {

relation: null,
counts: {},
computingClassCounts: false,
filteredCounts: {},
clp: {},
filters: new List(),
Expand Down Expand Up @@ -605,12 +606,21 @@ class Browser extends DashboardView {
});
}

handleFetchedSchema() {
this.props.schema.data.get('classes').forEach((_, className) => {
this.context.currentApp.getClassCount(className)
.then(count => this.setState({ counts: { [className]: count, ...this.state.counts } }));
})
this.setState({clp: this.props.schema.data.get('CLPs').toJS()});
async handleFetchedSchema() {
const counts = this.state.counts;
if (this.state.computingClassCounts === false) {
this.setState({ computingClassCounts: true });
for (const parseClass of this.props.schema.data.get('classes')) {
const [className] = parseClass;
counts[className] = await this.context.currentApp.getClassCount(className);
}

this.setState({
clp: this.props.schema.data.get('CLPs').toJS(),
counts,
computingClassCounts: false
});
}
}

async refresh() {
Expand Down