@@ -807,9 +807,8 @@ export default class SchemaController {
807807 className,
808808 } )
809809 ) ;
810- // TODO: Remove by updating schema cache directly
811- await this . reloadData ( { clearCache : true } ) ;
812810 const parseSchema = convertAdapterSchemaToParseSchema ( adapterSchema ) ;
811+ SchemaCache . set ( className , parseSchema ) ;
813812 return parseSchema ;
814813 } catch ( error ) {
815814 if ( error && error . code === Parse . Error . DUPLICATE_VALUE ) {
@@ -935,6 +934,7 @@ export default class SchemaController {
935934 return (
936935 // The schema update succeeded. Reload the schema
937936 this . addClassIfNotExists ( className )
937+ . then ( ( ) => this . reloadData ( ) )
938938 . catch ( ( ) => {
939939 // The schema update failed. This can be okay - it might
940940 // have failed because there's a race condition and a different
@@ -1060,12 +1060,7 @@ export default class SchemaController {
10601060 // object if the provided className-fieldName-type tuple is valid.
10611061 // The className must already be validated.
10621062 // 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 ) {
10691064 if ( fieldName . indexOf ( '.' ) > 0 ) {
10701065 // subdocument key (x.y) => ok if x is of type 'object'
10711066 fieldName = fieldName . split ( '.' ) [ 0 ] ;
@@ -1113,7 +1108,7 @@ export default class SchemaController {
11131108 }
11141109
11151110 return this . _dbAdapter
1116- . addFieldIfNotExists ( className , fieldName , type , transactionalSession )
1111+ . addFieldIfNotExists ( className , fieldName , type )
11171112 . catch ( error => {
11181113 if ( error . code == Parse . Error . INCORRECT_TYPE ) {
11191114 // Make sure that we throw errors when it is appropriate to do so.
@@ -1125,6 +1120,13 @@ export default class SchemaController {
11251120 return Promise . resolve ( ) ;
11261121 } )
11271122 . 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+ }
11281130 return {
11291131 className,
11301132 fieldName,
@@ -1214,7 +1216,7 @@ export default class SchemaController {
12141216 // Validates an object provided in REST format.
12151217 // Returns a promise that resolves to the new schema if this object is
12161218 // valid.
1217- async validateObject ( className : string , object : any , query : any , transactionalSession : ? any ) {
1219+ async validateObject ( className : string , object : any , query : any ) {
12181220 let geocount = 0 ;
12191221 const schema = await this . enforceClassExists ( className ) ;
12201222 const results = [ ] ;
@@ -1244,15 +1246,12 @@ export default class SchemaController {
12441246 // Every object has ACL implicitly.
12451247 continue ;
12461248 }
1247- results . push (
1248- await schema . enforceFieldExists ( className , fieldName , expected , transactionalSession )
1249- ) ;
1249+ results . push ( await schema . enforceFieldExists ( className , fieldName , expected ) ) ;
12501250 }
12511251 const enforceFields = results . filter ( result => ! ! result ) ;
12521252
12531253 if ( enforceFields . length !== 0 ) {
1254- // TODO: Remove by updating schema cache directly
1255- await this . reloadData ( { clearCache : true } ) ;
1254+ await this . reloadData ( ) ;
12561255 }
12571256 this . ensureFields ( enforceFields ) ;
12581257
0 commit comments