View Full Version : Synchronising store with server

9 Oct 2014, 11:12 AM
I am working on an application that has a number of stores that are loaded from the server. The store.load()ed records can be modified by the user/application and then saved back to the server using the model's save/destroy methods.

As records can also be modified and removed on the server side (potentially by other users of the same application) there is a need to synchronise the stores against any changes made on the server.

Is this is the purpose of the store.sync() method? If so, I am not sure how this method would deal with records that have been deleted at the server's side.. I am not really getting how sync() actually works by just reading the documentation and I couldn't find any examples.

If sync() isn't the right method for me, then is there a preferred method to accomplish this server to client updating without re-loading the entire store?

9 Oct 2014, 12:01 PM
Having looked at this a bit more I don't think sync() does what I want as I think it would just push changes made locally on the client to the server via the proxy.

To clarify what I am looking for: I could quite easily implement a timer to reload all my stores using reload() but that would be a huge waste of bandwidth as only a fraction of records will have been modified/removed at the server. I want something more efficient.

So instead I want the server to give a list of modified records (including which ones have been deleted) and that I then only update those records.

Is there anything built into ExtJs to help implementing this?

9 Oct 2014, 12:44 PM
This is a wide topic as your server would have to determine the changed records and then what is the amount of data sent back (stores)?
Is this is a grid, is the data paged or buffered, what is the interval

Is the time it takes to check for altered records worth the effort vs just sending limited data back to client?
Then you have to handle the changes at the client.


9 Oct 2014, 1:09 PM
Thanks Scott.. my current approach is to implement these functions myself in the following way.

I can quite easily figure out in my database which records have been changed since a given timestamp.

I have a few stores that are loaded from the server and each load is about ~1-3MB of json data. When the store is loaded I have a store load handler that will keep track of a timestamp (generated and sent by the server).

Now I would be able to issue a separate Ajax request to retrieve the records that have been modified, and the id's of records that have been deleted since timestamp.

I can then iterate over these to delete/update the relevant records in the store.

Would be interesting to hear your thoughts about it... :)

9 Oct 2014, 1:24 PM
>>> 1-3MB of json data

Is all of this displayed in grids at once? Is it required to send all of the data?

My initial thought is that this would be time consuming at the client level with that amount of data.

There are still some unknowns, so it would be hard to say.