@@ -282,13 +282,13 @@ class SchemaController {
282282 this . perms = { } ;
283283 }
284284
285- reloadData ( clearCache = false ) {
285+ reloadData ( options = { clearCache : false } ) {
286286 this . data = { } ;
287287 this . perms = { } ;
288- if ( clearCache ) {
288+ if ( options . clearCache ) {
289289 this . _cache . clear ( ) ;
290290 }
291- return this . getAllClasses ( clearCache )
291+ return this . getAllClasses ( options )
292292 . then ( allSchemas => {
293293 allSchemas . forEach ( schema => {
294294 this . data [ schema . className ] = injectDefaultSchema ( schema ) . fields ;
@@ -306,12 +306,12 @@ class SchemaController {
306306 } ) ;
307307 }
308308
309- getAllClasses ( clearCache = false ) {
310- if ( clearCache ) {
309+ getAllClasses ( options = { clearCache : false } ) {
310+ if ( options . clearCache ) {
311311 this . _cache . clear ( ) ;
312312 }
313313 return this . _cache . getAllClasses ( ) . then ( ( allClasses ) => {
314- if ( allClasses && allClasses . length && ! clearCache ) {
314+ if ( allClasses && allClasses . length && ! options . clearCache ) {
315315 return Promise . resolve ( allClasses ) ;
316316 }
317317 return this . _dbAdapter . getAllClasses ( )
@@ -323,17 +323,17 @@ class SchemaController {
323323 } ) ;
324324 }
325325
326- getOneSchema ( className , allowVolatileClasses = false , clearCache ) {
327- if ( clearCache ) {
326+ getOneSchema ( className , allowVolatileClasses = false , options = { clearCache : false } ) {
327+ if ( options . clearCache ) {
328328 this . _cache . clear ( ) ;
329329 }
330+ if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
331+ return Promise . resolve ( this . data [ className ] ) ;
332+ }
330333 return this . _cache . getOneSchema ( className ) . then ( ( cached ) => {
331- if ( cached && ! clearCache ) {
334+ if ( cached && ! options . clearCache ) {
332335 return Promise . resolve ( cached ) ;
333336 }
334- if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
335- return Promise . resolve ( this . data [ className ] ) ;
336- }
337337 return this . _dbAdapter . getClass ( className )
338338 . then ( injectDefaultSchema )
339339 . then ( ( result ) => {
@@ -407,7 +407,7 @@ class SchemaController {
407407 } ) ;
408408
409409 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
411411 . then ( ( ) => {
412412 let promises = insertedFields . map ( fieldName => {
413413 const type = submittedFields [ fieldName ] ;
@@ -441,13 +441,13 @@ class SchemaController {
441441 // We don't have this class. Update the schema
442442 return this . addClassIfNotExists ( className )
443443 // The schema update succeeded. Reload the schema
444- . then ( ( ) => this . reloadData ( true ) )
444+ . then ( ( ) => this . reloadData ( { clearCache : true } ) )
445445 . catch ( error => {
446446 // The schema update failed. This can be okay - it might
447447 // have failed because there's a race condition and a different
448448 // client is making the exact same schema update that we want.
449449 // So just reload the schema.
450- return this . reloadData ( true ) ;
450+ return this . reloadData ( { clearCache : true } ) ;
451451 } )
452452 . then ( ( ) => {
453453 // Ensure that the schema now validates
@@ -517,7 +517,7 @@ class SchemaController {
517517 }
518518 validateCLP ( perms , newSchema ) ;
519519 return this . _dbAdapter . setClassLevelPermissions ( className , perms )
520- . then ( ( ) => this . reloadData ( true ) ) ;
520+ . then ( ( ) => this . reloadData ( { clearCache : true } ) ) ;
521521 }
522522
523523 // Returns a promise that resolves successfully to the new schema
@@ -557,14 +557,14 @@ class SchemaController {
557557
558558 return this . _dbAdapter . addFieldIfNotExists ( className , fieldName , type ) . then ( ( ) => {
559559 // The update succeeded. Reload the schema
560- return this . reloadData ( true ) ;
560+ return this . reloadData ( { clearCache : true } ) ;
561561 } , error => {
562562 //TODO: introspect the error and only reload if the error is one for which is makes sense to reload
563563
564564 // The update failed. This can be okay - it might have been a race
565565 // condition where another client updated the schema in the same
566566 // way that we wanted to. So, just reload the schema
567- return this . reloadData ( true ) ;
567+ return this . reloadData ( { clearCache : true } ) ;
568568 } ) . then ( error => {
569569 // Ensure that the schema now validates
570570 if ( ! dbTypeMatchesObjectType ( this . getExpectedType ( className , fieldName ) , type ) ) {
@@ -596,7 +596,7 @@ class SchemaController {
596596 throw new Parse . Error ( 136 , `field ${ fieldName } cannot be changed` ) ;
597597 }
598598
599- return this . getOneSchema ( className , false , true )
599+ return this . getOneSchema ( className , false , { clearCache : true } )
600600 . catch ( error => {
601601 if ( error === undefined ) {
602602 throw new Parse . Error ( Parse . Error . INVALID_CLASS_NAME , `Class ${ className } does not exist.` ) ;
@@ -746,9 +746,9 @@ class SchemaController {
746746}
747747
748748// Returns a promise for a new Schema.
749- const load = ( dbAdapter , schemaCache , clearCache ) => {
749+ const load = ( dbAdapter , schemaCache , options ) => {
750750 let schema = new SchemaController ( dbAdapter , schemaCache ) ;
751- return schema . reloadData ( clearCache ) . then ( ( ) => schema ) ;
751+ return schema . reloadData ( options ) . then ( ( ) => schema ) ;
752752}
753753
754754// Builds a new schema (in schema API response format) out of an
0 commit comments