Skip to content

Commit fd73509

Browse files
committed
Fetch class counts using Parse Query
1 parent 7119f6d commit fd73509

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

dashboard/Data/Browser/Browser.react.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export default class Browser extends DashboardView {
6161
}
6262

6363
componentWillMount() {
64-
this.props.schema.dispatch(ActionTypes.FETCH);
64+
this.props.schema.dispatch(ActionTypes.FETCH)
65+
.then(() => this.fetchCollectionCounts());
6566
if (!this.props.params.className && this.props.schema.data.get('classes')) {
6667
this.redirectToFirstClass(this.props.schema.data.get('classes'));
6768
} else if (this.props.params.className) {
@@ -83,7 +84,8 @@ export default class Browser extends DashboardView {
8384

8485
componentWillReceiveProps(nextProps, nextContext) {
8586
if (this.context !== nextContext) {
86-
nextProps.schema.dispatch(ActionTypes.FETCH);
87+
nextProps.schema.dispatch(ActionTypes.FETCH)
88+
.then(() => this.fetchCollectionCounts());
8789
let changes = {
8890
filters: new List(),
8991
data: null,
@@ -220,6 +222,13 @@ export default class Browser extends DashboardView {
220222
});
221223
}
222224

225+
fetchCollectionCounts() {
226+
this.props.schema.data.get('classes').forEach((_, className) => {
227+
this.context.currentApp.getClassCount(className)
228+
.then(count => this.setState({ counts: { [className]: count, ...this.state.counts } }));
229+
})
230+
}
231+
223232
fetchInfo(app) {
224233
app.getCollectionInfo().then(({ collections }) => {
225234
let counts = {};

dashboard/Data/Browser/BrowserToolbar.react.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
import BrowserFilter from 'components/BrowserFilter/BrowserFilter.react';
9-
import BrowserMenu from 'components/BrowserMenu/BrowserMenu.react';
10-
import Icon from 'components/Icon/Icon.react';
11-
import MenuItem from 'components/BrowserMenu/MenuItem.react';
12-
import prettyNumber from 'lib/prettyNumber';
13-
import React from 'react';
14-
import SecurityDialog from 'dashboard/Data/Browser/SecurityDialog.react'
15-
import Separator from 'components/BrowserMenu/Separator.react';
16-
import Toolbar from 'components/Toolbar/Toolbar.react';
17-
import styles from 'dashboard/Data/Browser/Browser.scss';
8+
import BrowserFilter from 'components/BrowserFilter/BrowserFilter.react';
9+
import BrowserMenu from 'components/BrowserMenu/BrowserMenu.react';
10+
import Icon from 'components/Icon/Icon.react';
11+
import MenuItem from 'components/BrowserMenu/MenuItem.react';
12+
import prettyNumber from 'lib/prettyNumber';
13+
import React from 'react';
14+
import SecurityDialog from 'dashboard/Data/Browser/SecurityDialog.react';
15+
import Separator from 'components/BrowserMenu/Separator.react';
16+
import styles from 'dashboard/Data/Browser/Browser.scss';
17+
import Toolbar from 'components/Toolbar/Toolbar.react';
1818

1919
let BrowserToolbar = ({
2020
className,

lib/ParseApp.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export default class ParseApp {
7373
lastFetched: new Date(0)
7474
};
7575

76+
this.classCounts = {
77+
counts: {},
78+
lastFetched: {},
79+
}
80+
7681
this.hasCheckedForMigraton = false;
7782
}
7883

@@ -181,6 +186,22 @@ export default class ParseApp {
181186
});
182187
}
183188

189+
getClassCount(className) {
190+
this.setParseKeys();
191+
if (this.classCounts.counts[className] !== undefined) {
192+
// Cache it for a minute
193+
if (new Date() - this.classCounts.lastFetched[className] < 60000) {
194+
return Parse.Promise.as(this.classCounts.counts[className]);
195+
}
196+
}
197+
let p = new Parse.Query(className).count({ useMasterKey: true });
198+
p.then(count => {
199+
this.classCounts.counts[className] = count;
200+
this.classCounts.lastFetched[className] = new Date();
201+
})
202+
return p;
203+
}
204+
184205
getAnalyticsRetention(time) {
185206
time = Math.round(time.getTime() / 1000);
186207
return AJAX.abortableGet('/apps/' + this.slug + '/analytics_retention?at=' + time);

0 commit comments

Comments
 (0)