PDA

View Full Version : How to avoid autoSave store from sending multiple requests to the server? (esp. Add)



Greg.Veres
27 Feb 2011, 11:02 AM
We are using the autoSave = true setting on our store with a CXF backend.

What we just found out while testing with a system with some round trip delay, is that the store will send multiple requests to the server for the same store operation, this is fine for updates, but is really bothersome for adds.

We are using the restful store setting so our URLs are POST for create, PUT for update.

What we find is that when the user clicks on a button to add a new record to the store, the server will send a POST to add the new record. Then if the user continues to interact with the page and edits another record, the store than sends the original POST again and a new PUT to do the update on the second record.

This translates to:
store.add() -> sends initial Post
record.set(..) -> sends initial Post and new PUT, if the POST hasn't been responded to yet.

This seems like a bug to me. I would have expected the store to only send the PUT because it knew that it had an outstanding request for the original POST. Then if the POST times out, it can send the POST again.

Are we using it wrong? What is the common way that people code around this problem? We really can't afford to have the POSTs called multiple times for the same record, nor is it desirable to block the usage of the app any time that the user does an action that results in a POST.

Any suggestions?
Thanks
Greg