After having some issues with long wait times for my saving process I’ve decided to add a batch
boolean option to the save function on RecordArrays, as well as a global option to set the default value to true/false.
This option would collect all dirty records in the array and send one or two requests, one to the api batch create route for the resource if there are any new records and one to the api batch update route if there are any updated records.
The format of the data sent would be the same as whatever the adapter/serializer expects to receive for batch finds (i.e. findAll
and findQuery
). So in the case of the ActiveModel adapter, a batch save would look like so:
{
"posts": [
{ "title": "Foo", "text": "..." },
{ "title": "Bar", "text": "..." },
{ "title": "Baz", "text": "..." }
]
}
My questions regarding this modification are:
- Would this be a useful feature to pull into the main codebase?
- If so, does the described process seem adequate?
In addition, since I would be editing some of the relevant parts of the ActiveModel adapter, I was considering bringing it closer to JSONAPI by addressing this issue. I would either include an option to singularize or pluralize (depending on which is default) the single item save. Questions here are:
- Is JSONAPI compliance the goal of the ActiveModel adapter?
- If so, should the default behavior be to encapsulate all objects in an array w/ a pluralized key, providing an option to singularize OR should it be the reverse?