Search code examples
herokuparse-server

Parse Server - Saving objects with many fields - Schema Validation takes too long (enforceFieldExists)


We're using ParseServer to migrate a CloudCode based application to Heroku. Using versions:

  • parse@1.8.5
  • parse-server@2.2.16

We noticed (its hard not to notice) that saving some is unreasonably slow. These objects are typically saved a few at a time - between 2 to 6 objects (using an Parse.Object.saveAll which fires a REST call to /1/batch

Saving each of these objects now takes anything between 4 to 12 seconds. Digging into Parse code, it was easy to see that schema validation is the cause.

SchemaController.validateObject() {
...
SchemaController.enforceFieldExists()

We are using triggers for simple validation, but as per the logic in RestWrite.js this causes schema validation to be executed twice - once before trigger and once after.

The problem lies in that our collection has about 40 fields. SchemaController.enforceFieldExists() loads the entire schema twice while attempting to validate each field. Moreover, it always attempts to write to the schema document (again, for each field), only to fail usually because all fields are already listed in the schema.

this means that we get an overhead of about 240 round trips to the database for each object, and we store up to 5 objects typically in each invocation. that adds up to over 1000 round trips to the database. so we easily go beyond the Heroku router timeout limit of 30 seconds.

My questions are:

  1. Is there anything I can do to speed up this validation? (did not find documentation or settings for that)
  2. Is there a fix for this redundant implementation planned or available anywhere?
  3. Can I safely castrate enforceFieldExists() to do nothing without anything else breaking on me assuming we don't add fields often? What is this collection (_SCHEMA) used for other tan to draw the tables in Dashboard UI?
  4. I'm currently thinking about patching this function to do nothing with an npm postinstall script. Does that sound like a good approach?

Appreciate any help on this, Ron


Solution

  • This is being fixed with this pull request https://github.com/ParsePlatform/parse-server/pull/2286

    and that line https://github.com/ParsePlatform/parse-server/pull/2286/files#diff-7d0dd667d7bdafd6ebee06cf70139fa0R555

    This will skip trying to write the schema is the current field is available.

    This should be released soon