@@ -807,9 +807,8 @@ export default class SchemaController {
807
807
className,
808
808
} )
809
809
) ;
810
- // TODO: Remove by updating schema cache directly
811
- await this . reloadData ( { clearCache : true } ) ;
812
810
const parseSchema = convertAdapterSchemaToParseSchema ( adapterSchema ) ;
811
+ SchemaCache . set ( className , parseSchema ) ;
813
812
return parseSchema ;
814
813
} catch ( error ) {
815
814
if ( error && error . code === Parse . Error . DUPLICATE_VALUE ) {
@@ -935,6 +934,7 @@ export default class SchemaController {
935
934
return (
936
935
// The schema update succeeded. Reload the schema
937
936
this . addClassIfNotExists ( className )
937
+ . then ( ( ) => this . reloadData ( ) )
938
938
. catch ( ( ) => {
939
939
// The schema update failed. This can be okay - it might
940
940
// have failed because there's a race condition and a different
@@ -1060,12 +1060,7 @@ export default class SchemaController {
1060
1060
// object if the provided className-fieldName-type tuple is valid.
1061
1061
// The className must already be validated.
1062
1062
// If 'freeze' is true, refuse to update the schema for this field.
1063
- enforceFieldExists (
1064
- className : string ,
1065
- fieldName : string ,
1066
- type : string | SchemaField ,
1067
- transactionalSession : ?any
1068
- ) {
1063
+ enforceFieldExists ( className : string , fieldName : string , type : string | SchemaField ) {
1069
1064
if ( fieldName . indexOf ( '.' ) > 0 ) {
1070
1065
// subdocument key (x.y) => ok if x is of type 'object'
1071
1066
fieldName = fieldName . split ( '.' ) [ 0 ] ;
@@ -1113,7 +1108,7 @@ export default class SchemaController {
1113
1108
}
1114
1109
1115
1110
return this . _dbAdapter
1116
- . addFieldIfNotExists ( className , fieldName , type , transactionalSession )
1111
+ . addFieldIfNotExists ( className , fieldName , type )
1117
1112
. catch ( error => {
1118
1113
if ( error . code == Parse . Error . INCORRECT_TYPE ) {
1119
1114
// Make sure that we throw errors when it is appropriate to do so.
@@ -1125,6 +1120,13 @@ export default class SchemaController {
1125
1120
return Promise . resolve ( ) ;
1126
1121
} )
1127
1122
. then ( ( ) => {
1123
+ const cached = SchemaCache . get ( className ) ;
1124
+ if ( cached ) {
1125
+ if ( cached && ! cached . fields [ fieldName ] ) {
1126
+ cached . fields [ fieldName ] = type ;
1127
+ SchemaCache . set ( className , cached ) ;
1128
+ }
1129
+ }
1128
1130
return {
1129
1131
className,
1130
1132
fieldName,
@@ -1214,7 +1216,7 @@ export default class SchemaController {
1214
1216
// Validates an object provided in REST format.
1215
1217
// Returns a promise that resolves to the new schema if this object is
1216
1218
// valid.
1217
- async validateObject ( className : string , object : any , query : any , transactionalSession : ? any ) {
1219
+ async validateObject ( className : string , object : any , query : any ) {
1218
1220
let geocount = 0 ;
1219
1221
const schema = await this . enforceClassExists ( className ) ;
1220
1222
const results = [ ] ;
@@ -1244,15 +1246,12 @@ export default class SchemaController {
1244
1246
// Every object has ACL implicitly.
1245
1247
continue ;
1246
1248
}
1247
- results . push (
1248
- await schema . enforceFieldExists ( className , fieldName , expected , transactionalSession )
1249
- ) ;
1249
+ results . push ( await schema . enforceFieldExists ( className , fieldName , expected ) ) ;
1250
1250
}
1251
1251
const enforceFields = results . filter ( result => ! ! result ) ;
1252
1252
1253
1253
if ( enforceFields . length !== 0 ) {
1254
- // TODO: Remove by updating schema cache directly
1255
- await this . reloadData ( { clearCache : true } ) ;
1254
+ await this . reloadData ( ) ;
1256
1255
}
1257
1256
this . ensureFields ( enforceFields ) ;
1258
1257
0 commit comments