Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify if 'clearing the collection' affects only client, or client+server #114

Closed
michielbdejong opened this issue Aug 13, 2015 · 9 comments
Assignees
Milestone

Comments

@michielbdejong
Copy link
Contributor

Sometimes I will want to remove all the items from the collection on the server.
Other times (actually, probably only when debugging, or maybe when offline and offering the user something like git checkout -- . to discard unpushed changes), I only want to flush the cache, to make sync start from zero.
It is not clear to me which one of these two is done by http://kintojs.readthedocs.org/en/latest/api/#clearing-the-collection

@leplatrem
Copy link
Contributor

Currently collection.clear() will only clear the local store (records + last sync etag). Hence, if I'm not wrong, it will behave as git checkout --.

In order to remove all items on the server, so far there is no way to do it from kinto.js. It can be done on the API using a DELETE /buckets/{..}/collections/{...}/records though.

What would you suggest to implement this ? Adding a flush option to sync() ? a flush() method ? Don't hesitate to write some dream code, and we'll iterate on that :)

@Natim
Copy link
Member

Natim commented Aug 13, 2015

I my opinion, collection.clear() should mark all records of the collection as deleted and should try to delete them during the next sync.

@leplatrem
Copy link
Contributor

I my opinion, collection.clear() should mark all records of the collection as deleted and should try to delete them during the next sync.

Instead, to be consistent with remote API, I would suggest to have a bulk delete method on the collection (with same params as list()).

collection.delete({filters: {complete: true})

@michielbdejong
Copy link
Contributor Author

For me, having collection.clear() is enough! I just found the phrase 'This will remove all existing records from the collection' in the documentation a bit scary, I was afraid it would wipe the server.

@michielbdejong
Copy link
Contributor Author

Oh, another thing that surprised me just now is that if I call .clear() and then call .sync(), the records don't reappear. So it's not just a flushing of the cache.

@michielbdejong
Copy link
Contributor Author

Work-around to 'flush the cache' on a collection is to call indexedDB.deleteDatabase from the console, using 'bucket/collection' as the databaseName (so for instance 'syncto/history'). That has the effect I was expecting .clear() to have.

@n1k0
Copy link
Contributor

n1k0 commented Aug 24, 2015

Oh, another thing that surprised me just now is that if I call .clear() and then call .sync(), the records don't reappear.

That's probably a bug.

Also, I don't think it's a good idea to wipe data on the server when .clear is called locally — sounds so much catastrophe-prone… Maybe adding an option to the method, eg. .clear({sync: true}) + proper docs would be enough to avoid embarrassing situations.

@n1k0 n1k0 added this to the 1.0.0 milestone Sep 15, 2015
@n1k0
Copy link
Contributor

n1k0 commented Sep 15, 2015

While pairing with @ametaireau, we discovered than after clear()ing a collection, metadata were kept — namely collection's lastModified value; we should probably drop these as well.

@michielbdejong
Copy link
Contributor Author

Yeah, that was probably what caused the behavior that surprised me.

@n1k0 n1k0 self-assigned this Oct 22, 2015
@n1k0 n1k0 closed this as completed in 06413a9 Oct 22, 2015
n1k0 added a commit that referenced this issue Oct 22, 2015
@n1k0 n1k0 removed the in progress label Oct 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants