17
17
// @flow -disable-next
18
18
const Parse = require ( 'parse/node' ) . Parse ;
19
19
import { StorageAdapter } from '../Adapters/Storage/StorageAdapter' ;
20
+ import SchemaCache from '../Adapters/Cache/SchemaCache' ;
20
21
import DatabaseController from './DatabaseController' ;
21
22
import Config from '../Config' ;
22
23
// @flow -disable-next
@@ -682,15 +683,13 @@ const typeToString = (type: SchemaField | string): string => {
682
683
export default class SchemaController {
683
684
_dbAdapter : StorageAdapter ;
684
685
schemaData : { [ string ] : Schema } ;
685
- _cache: any ;
686
686
reloadDataPromise: ?Promise < any > ;
687
687
protectedFields: any ;
688
688
userIdRegEx: RegExp ;
689
689
690
- constructor ( databaseAdapter : StorageAdapter , singleSchemaCache : Object ) {
690
+ constructor ( databaseAdapter : StorageAdapter ) {
691
691
this . _dbAdapter = databaseAdapter ;
692
- this . _cache = singleSchemaCache ;
693
- this . schemaData = new SchemaData ( this . _cache . allClasses || [ ] , this . protectedFields ) ;
692
+ this . schemaData = new SchemaData ( SchemaCache . get ( ) , this . protectedFields ) ;
694
693
this . protectedFields = Config . get ( Parse . applicationId ) . protectedFields ;
695
694
696
695
const customIds = Config . get ( Parse . applicationId ) . allowCustomObjectId ;
@@ -729,8 +728,9 @@ export default class SchemaController {
729
728
if ( options . clearCache ) {
730
729
return this . setAllClasses ( ) ;
731
730
}
732
- if ( this . _cache . allClasses && this . _cache . allClasses . length ) {
733
- return Promise . resolve ( this . _cache . allClasses ) ;
731
+ const cached = SchemaCache . get ( ) ;
732
+ if ( cached && cached . length ) {
733
+ return Promise . resolve ( cached ) ;
734
734
}
735
735
return this . setAllClasses ( ) ;
736
736
}
@@ -740,7 +740,7 @@ export default class SchemaController {
740
740
. getAllClasses ( )
741
741
. then ( allSchemas => allSchemas . map ( injectDefaultSchema ) )
742
742
. then ( allSchemas => {
743
- this . _cache . allClasses = allSchemas ;
743
+ SchemaCache . put ( allSchemas ) ;
744
744
return allSchemas ;
745
745
} ) ;
746
746
}
@@ -751,7 +751,7 @@ export default class SchemaController {
751
751
options : LoadSchemaOptions = { clearCache : false }
752
752
) : Promise < Schema > {
753
753
if ( options . clearCache ) {
754
- delete this . _cache . allClasses ;
754
+ SchemaCache . clear ( ) ;
755
755
}
756
756
if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
757
757
const data = this . schemaData [ className ] ;
@@ -762,7 +762,7 @@ export default class SchemaController {
762
762
indexes : data . indexes ,
763
763
} ) ;
764
764
}
765
- const cached = ( this . _cache . allClasses || [ ] ) . find ( schema => schema . className === className ) ;
765
+ const cached = SchemaCache . get ( ) . find ( schema => schema . className === className ) ;
766
766
if ( cached && ! options . clearCache ) {
767
767
return Promise . resolve ( cached ) ;
768
768
}
@@ -1050,7 +1050,7 @@ export default class SchemaController {
1050
1050
}
1051
1051
validateCLP ( perms , newSchema , this . userIdRegEx ) ;
1052
1052
await this . _dbAdapter . setClassLevelPermissions ( className , perms ) ;
1053
- const cached = ( this . _cache . allClasses || [ ] ) . find ( schema => schema . className === className ) ;
1053
+ const cached = SchemaCache . get ( ) . find ( schema => schema . className === className ) ;
1054
1054
if ( cached ) {
1055
1055
cached . classLevelPermissions = perms ;
1056
1056
}
@@ -1202,7 +1202,7 @@ export default class SchemaController {
1202
1202
} ) ;
1203
1203
} )
1204
1204
. then ( ( ) => {
1205
- delete this . _cache . allClasses ;
1205
+ SchemaCache . clear ( ) ;
1206
1206
} ) ;
1207
1207
}
1208
1208
@@ -1412,20 +1412,12 @@ export default class SchemaController {
1412
1412
}
1413
1413
}
1414
1414
1415
- const singleSchemaCache = { } ;
1416
-
1417
1415
// Returns a promise for a new Schema.
1418
1416
const load = ( dbAdapter : StorageAdapter , options : any ) : Promise < SchemaController > => {
1419
- const schema = new SchemaController ( dbAdapter , singleSchemaCache ) ;
1417
+ const schema = new SchemaController ( dbAdapter ) ;
1420
1418
return schema . reloadData ( options ) . then ( ( ) => schema ) ;
1421
1419
} ;
1422
1420
1423
- const clearSingleSchemaCache = ( ) => {
1424
- delete singleSchemaCache . allClasses ;
1425
- } ;
1426
-
1427
- const getSingleSchemaCache = ( ) => singleSchemaCache . allClasses ;
1428
-
1429
1421
// Builds a new schema (in schema API response format) out of an
1430
1422
// existing mongo schema + a schemas API put request. This response
1431
1423
// does not include the default fields, as it is intended to be passed
@@ -1585,8 +1577,6 @@ function getObjectType(obj): ?(SchemaField | string) {
1585
1577
1586
1578
export {
1587
1579
load ,
1588
- clearSingleSchemaCache ,
1589
- getSingleSchemaCache ,
1590
1580
classNameIsValid ,
1591
1581
fieldNameIsValid ,
1592
1582
invalidClassNameMessage ,
0 commit comments