File tree Expand file tree Collapse file tree 3 files changed +42
-12
lines changed Expand file tree Collapse file tree 3 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ export default class Browser extends DashboardView {
61
61
}
62
62
63
63
componentWillMount ( ) {
64
- this . props . schema . dispatch ( ActionTypes . FETCH ) ;
64
+ this . props . schema . dispatch ( ActionTypes . FETCH )
65
+ . then ( ( ) => this . fetchCollectionCounts ( ) ) ;
65
66
if ( ! this . props . params . className && this . props . schema . data . get ( 'classes' ) ) {
66
67
this . redirectToFirstClass ( this . props . schema . data . get ( 'classes' ) ) ;
67
68
} else if ( this . props . params . className ) {
@@ -83,7 +84,8 @@ export default class Browser extends DashboardView {
83
84
84
85
componentWillReceiveProps ( nextProps , nextContext ) {
85
86
if ( this . context !== nextContext ) {
86
- nextProps . schema . dispatch ( ActionTypes . FETCH ) ;
87
+ nextProps . schema . dispatch ( ActionTypes . FETCH )
88
+ . then ( ( ) => this . fetchCollectionCounts ( ) ) ;
87
89
let changes = {
88
90
filters : new List ( ) ,
89
91
data : null ,
@@ -220,6 +222,13 @@ export default class Browser extends DashboardView {
220
222
} ) ;
221
223
}
222
224
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
+
223
232
fetchInfo ( app ) {
224
233
app . getCollectionInfo ( ) . then ( ( { collections } ) => {
225
234
let counts = { } ;
Original file line number Diff line number Diff line change 5
5
* This source code is licensed under the license found in the LICENSE file in
6
6
* the root directory of this source tree.
7
7
*/
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 ' ;
18
18
19
19
let BrowserToolbar = ( {
20
20
className,
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ export default class ParseApp {
73
73
lastFetched : new Date ( 0 )
74
74
} ;
75
75
76
+ this . classCounts = {
77
+ counts : { } ,
78
+ lastFetched : { } ,
79
+ }
80
+
76
81
this . hasCheckedForMigraton = false ;
77
82
}
78
83
@@ -181,6 +186,22 @@ export default class ParseApp {
181
186
} ) ;
182
187
}
183
188
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
+
184
205
getAnalyticsRetention ( time ) {
185
206
time = Math . round ( time . getTime ( ) / 1000 ) ;
186
207
return AJAX . abortableGet ( '/apps/' + this . slug + '/analytics_retention?at=' + time ) ;
You can’t perform that action at this time.
0 commit comments