@@ -282,13 +282,13 @@ class SchemaController {
282
282
this . perms = { } ;
283
283
}
284
284
285
- reloadData ( clearCache = false ) {
285
+ reloadData ( options = { clearCache : false } ) {
286
286
this . data = { } ;
287
287
this . perms = { } ;
288
- if ( clearCache ) {
288
+ if ( options . clearCache ) {
289
289
this . _cache . clear ( ) ;
290
290
}
291
- return this . getAllClasses ( clearCache )
291
+ return this . getAllClasses ( options )
292
292
. then ( allSchemas => {
293
293
allSchemas . forEach ( schema => {
294
294
this . data [ schema . className ] = injectDefaultSchema ( schema ) . fields ;
@@ -306,12 +306,12 @@ class SchemaController {
306
306
} ) ;
307
307
}
308
308
309
- getAllClasses ( clearCache = false ) {
310
- if ( clearCache ) {
309
+ getAllClasses ( options = { clearCache : false } ) {
310
+ if ( options . clearCache ) {
311
311
this . _cache . clear ( ) ;
312
312
}
313
313
return this . _cache . getAllClasses ( ) . then ( ( allClasses ) => {
314
- if ( allClasses && allClasses . length && ! clearCache ) {
314
+ if ( allClasses && allClasses . length && ! options . clearCache ) {
315
315
return Promise . resolve ( allClasses ) ;
316
316
}
317
317
return this . _dbAdapter . getAllClasses ( )
@@ -323,17 +323,17 @@ class SchemaController {
323
323
} ) ;
324
324
}
325
325
326
- getOneSchema ( className , allowVolatileClasses = false , clearCache ) {
327
- if ( clearCache ) {
326
+ getOneSchema ( className , allowVolatileClasses = false , options = { clearCache : false } ) {
327
+ if ( options . clearCache ) {
328
328
this . _cache . clear ( ) ;
329
329
}
330
+ if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
331
+ return Promise . resolve ( this . data [ className ] ) ;
332
+ }
330
333
return this . _cache . getOneSchema ( className ) . then ( ( cached ) => {
331
- if ( cached && ! clearCache ) {
334
+ if ( cached && ! options . clearCache ) {
332
335
return Promise . resolve ( cached ) ;
333
336
}
334
- if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
335
- return Promise . resolve ( this . data [ className ] ) ;
336
- }
337
337
return this . _dbAdapter . getClass ( className )
338
338
. then ( injectDefaultSchema )
339
339
. then ( ( result ) => {
@@ -407,7 +407,7 @@ class SchemaController {
407
407
} ) ;
408
408
409
409
return Promise . all ( deletePromises ) // Delete Everything
410
- . then ( ( ) => this . reloadData ( true ) ) // Reload our Schema, so we have all the new values
410
+ . then ( ( ) => this . reloadData ( { clearCache : true } ) ) // Reload our Schema, so we have all the new values
411
411
. then ( ( ) => {
412
412
let promises = insertedFields . map ( fieldName => {
413
413
const type = submittedFields [ fieldName ] ;
@@ -441,13 +441,13 @@ class SchemaController {
441
441
// We don't have this class. Update the schema
442
442
return this . addClassIfNotExists ( className )
443
443
// The schema update succeeded. Reload the schema
444
- . then ( ( ) => this . reloadData ( true ) )
444
+ . then ( ( ) => this . reloadData ( { clearCache : true } ) )
445
445
. catch ( error => {
446
446
// The schema update failed. This can be okay - it might
447
447
// have failed because there's a race condition and a different
448
448
// client is making the exact same schema update that we want.
449
449
// So just reload the schema.
450
- return this . reloadData ( true ) ;
450
+ return this . reloadData ( { clearCache : true } ) ;
451
451
} )
452
452
. then ( ( ) => {
453
453
// Ensure that the schema now validates
@@ -517,7 +517,7 @@ class SchemaController {
517
517
}
518
518
validateCLP ( perms , newSchema ) ;
519
519
return this . _dbAdapter . setClassLevelPermissions ( className , perms )
520
- . then ( ( ) => this . reloadData ( true ) ) ;
520
+ . then ( ( ) => this . reloadData ( { clearCache : true } ) ) ;
521
521
}
522
522
523
523
// Returns a promise that resolves successfully to the new schema
@@ -557,14 +557,14 @@ class SchemaController {
557
557
558
558
return this . _dbAdapter . addFieldIfNotExists ( className , fieldName , type ) . then ( ( ) => {
559
559
// The update succeeded. Reload the schema
560
- return this . reloadData ( true ) ;
560
+ return this . reloadData ( { clearCache : true } ) ;
561
561
} , error => {
562
562
//TODO: introspect the error and only reload if the error is one for which is makes sense to reload
563
563
564
564
// The update failed. This can be okay - it might have been a race
565
565
// condition where another client updated the schema in the same
566
566
// way that we wanted to. So, just reload the schema
567
- return this . reloadData ( true ) ;
567
+ return this . reloadData ( { clearCache : true } ) ;
568
568
} ) . then ( error => {
569
569
// Ensure that the schema now validates
570
570
if ( ! dbTypeMatchesObjectType ( this . getExpectedType ( className , fieldName ) , type ) ) {
@@ -596,7 +596,7 @@ class SchemaController {
596
596
throw new Parse . Error ( 136 , `field ${ fieldName } cannot be changed` ) ;
597
597
}
598
598
599
- return this . getOneSchema ( className , false , true )
599
+ return this . getOneSchema ( className , false , { clearCache : true } )
600
600
. catch ( error => {
601
601
if ( error === undefined ) {
602
602
throw new Parse . Error ( Parse . Error . INVALID_CLASS_NAME , `Class ${ className } does not exist.` ) ;
@@ -746,9 +746,9 @@ class SchemaController {
746
746
}
747
747
748
748
// Returns a promise for a new Schema.
749
- const load = ( dbAdapter , schemaCache , clearCache ) => {
749
+ const load = ( dbAdapter , schemaCache , options ) => {
750
750
let schema = new SchemaController ( dbAdapter , schemaCache ) ;
751
- return schema . reloadData ( clearCache ) . then ( ( ) => schema ) ;
751
+ return schema . reloadData ( options ) . then ( ( ) => schema ) ;
752
752
}
753
753
754
754
// Builds a new schema (in schema API response format) out of an
0 commit comments