Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Properly account for partial updates (fetching a subset of a collection). #90

Open
mikeric opened this issue Feb 15, 2014 · 1 comment

Comments

@mikeric
Copy link

mikeric commented Feb 15, 2014

For perf reasons, our API accepts a since parameter and only returns items that have changed since that time (typically it's the last time that the particular client has synced), so that we can update only the models that have changed on the client.

When fetching from the API in this way, we need to pass {remove: false} to the fetch (this is so that the unchanged items are not removed from the collection).

items.fetch({
  data: {since: 1392487594},
  remove: false
})

The issue here is that all items which were not included in that fetch's response are removed from localstorage (essentially ignoring the {remove: false} option that we've set on the fetch), so even though the collection has all the items at this point, the next time you fetch from localstorage, they will be gone, and you'll only end up with the items that were returned from the last fetch.

Is there an alternative method to accomplish this sort of thing using Backbone.dualStorage? If not, would it be trivial enough to store the actual collection's models in localstorage (after a fetch) rather than just the request's response data?

@nilbus
Copy link
Owner

nilbus commented Feb 16, 2014

Yes, you're right that dualStorage does not currently account for remove: false. I don't know of any workaround for your situation. We should add support for this option when fetching collections.

Adding support may be as simple as changing backbone.dualstorage.coffee:272 to:

localsync('clear', model, options) unless options.add or options.remove == false

I do not have time to test this out right now. First, see if this change fixes your specific issue in your project, and report back. If possible, please create a pull request that adds a unit and/or integration test that reproduces this failure before a fix is applied, and with the fix, if it works. See the README for test and build instructions.

Thanks!

@nilbus nilbus self-assigned this Feb 16, 2014
@nilbus nilbus removed their assignment May 10, 2014
@nilbus nilbus added this to the 2.0 milestone Jul 7, 2014
@nilbus nilbus modified the milestone: 2.0 May 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants