Bulk model.save() operations?

I've been looking through the Backbone documentation and sidecar/src, but I can't see a way this can be done.

We have a custom view with a tree/table view that combines multiple custom models and inline editing/calculation rollups.  Dirty models are tracked, and then there's a method that iterates through all the dirty models calling model.save().

Is there any way to queue these up and use the bulk api to send those .save() requests?

Parents
  • Sure Jeff.  We're using custom modules but it's similar to Opportunities and Revenue Line Items with a few additional layers.

    Something like: Opportunities > Options > Countries > Audiences > Revenue Line Items + Service Fees.

    On the Option view, there's a table that shows all of the child models and allows for inline editing (1 model at a time), with realtime rendering of the cost/price/discount fields.  I.e. if you set a discount at the audience level, it will roll down to all RLI and Service Fee items.

    If the user changes a pricing value at the option or country level, it has to roll calculations down to all the child RLI and Service Fees.

    This requires saving all of the child models.  Since we don't limit the number of countries/audiences/etc the user can create, this can result in dozens of model.save() operations which trigger individual API requests.

    While I would love to move all of the existing business logic into a single API endpoint, it's just not feasible at this time.  What I'm hoping to do is find a way to bulk the API requests to at least reduce the overhead/round trip cost of doing 60+ model.saves().

  • You can use the bulk API to include all 60 saves. Then you send one API request with all of the other API requests embedded in the first request. You'll have to include a timeout as part of the save. Otherwise, Sugar will timeout before all 60 saves are processed. 

  • Though because they're model updates, I assume I'll have to build out each individual API call for the BULK post, and then re-sync the response back to the models somehow?  I had thought about this months ago but was worried the models would get out of sync so I avoided it, was hoping there was some magic backbone method I wasn't seeing in the docs.

  • rereading your Use Case:

    If you save the change. Use a Logic Hook to update all of the related records. When the save is complete. You can reload the subpanels which will reflect the latest data in the UX

Reply Children
No Data