@@ -323,15 +323,20 @@ export default class SchemaController {
323
323
}
324
324
325
325
reloadData ( options = { clearCache : false } ) {
326
+ let promise = Promise . resolve ( ) ;
326
327
if ( options . clearCache ) {
327
- this . _cache . clear ( ) ;
328
+ promise = promise . then ( ( ) => {
329
+ return this . _cache . clear ( ) ;
330
+ } ) ;
328
331
}
329
332
if ( this . reloadDataPromise && ! options . clearCache ) {
330
333
return this . reloadDataPromise ;
331
334
}
332
335
this . data = { } ;
333
336
this . perms = { } ;
334
- this . reloadDataPromise = this . getAllClasses ( options )
337
+ this . reloadDataPromise = promise . then ( ( ) => {
338
+ return this . getAllClasses ( options ) ;
339
+ } )
335
340
. then ( allSchemas => {
336
341
allSchemas . forEach ( schema => {
337
342
this . data [ schema . className ] = injectDefaultSchema ( schema ) . fields ;
@@ -355,10 +360,13 @@ export default class SchemaController {
355
360
}
356
361
357
362
getAllClasses ( options = { clearCache : false } ) {
363
+ let promise = Promise . resolve ( ) ;
358
364
if ( options . clearCache ) {
359
- this . _cache . clear ( ) ;
365
+ promise = this . _cache . clear ( ) ;
360
366
}
361
- return this . _cache . getAllClasses ( ) . then ( ( allClasses ) => {
367
+ return promise . then ( ( ) => {
368
+ return this . _cache . getAllClasses ( )
369
+ } ) . then ( ( allClasses ) => {
362
370
if ( allClasses && allClasses . length && ! options . clearCache ) {
363
371
return Promise . resolve ( allClasses ) ;
364
372
}
@@ -373,22 +381,25 @@ export default class SchemaController {
373
381
}
374
382
375
383
getOneSchema ( className , allowVolatileClasses = false , options = { clearCache : false } ) {
384
+ let promise = Promise . resolve ( ) ;
376
385
if ( options . clearCache ) {
377
- this . _cache . clear ( ) ;
378
- }
379
- if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
380
- return Promise . resolve ( this . data [ className ] ) ;
386
+ promise = this . _cache . clear ( ) ;
381
387
}
382
- return this . _cache . getOneSchema ( className ) . then ( ( cached ) => {
383
- if ( cached && ! options . clearCache ) {
384
- return Promise . resolve ( cached ) ;
388
+ return promise . then ( ( ) => {
389
+ if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
390
+ return Promise . resolve ( this . data [ className ] ) ;
385
391
}
386
- return this . _dbAdapter . getClass ( className )
387
- . then ( injectDefaultSchema )
388
- . then ( ( result ) => {
389
- return this . _cache . setOneSchema ( className , result ) . then ( ( ) => {
390
- return result ;
391
- } )
392
+ return this . _cache . getOneSchema ( className ) . then ( ( cached ) => {
393
+ if ( cached && ! options . clearCache ) {
394
+ return Promise . resolve ( cached ) ;
395
+ }
396
+ return this . _dbAdapter . getClass ( className )
397
+ . then ( injectDefaultSchema )
398
+ . then ( ( result ) => {
399
+ return this . _cache . setOneSchema ( className , result ) . then ( ( ) => {
400
+ return result ;
401
+ } )
402
+ } ) ;
392
403
} ) ;
393
404
} ) ;
394
405
}
@@ -409,8 +420,9 @@ export default class SchemaController {
409
420
return this . _dbAdapter . createClass ( className , convertSchemaToAdapterSchema ( { fields, classLevelPermissions, className } ) )
410
421
. then ( convertAdapterSchemaToParseSchema )
411
422
. then ( ( res ) => {
412
- this . _cache . clear ( ) ;
413
- return res ;
423
+ return this . _cache . clear ( ) . then ( ( ) => {
424
+ return Promise . resolve ( res ) ;
425
+ } ) ;
414
426
} )
415
427
. catch ( error => {
416
428
if ( error && error . code === Parse . Error . DUPLICATE_VALUE ) {
@@ -508,6 +520,7 @@ export default class SchemaController {
508
520
}
509
521
} )
510
522
. catch ( error => {
523
+ console . error ( error ) ;
511
524
// The schema still doesn't validate. Give up
512
525
throw new Parse . Error ( Parse . Error . INVALID_JSON , 'schema class name does not revalidate' ) ;
513
526
} ) ;
0 commit comments