-
Notifications
You must be signed in to change notification settings - Fork 76
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
Server side deletion doesn't update store #11
Comments
Which version of Pouch are you using, which version of CouchDB? |
I just installed ember-pouch using bower yesterday. ember 1.5.1 |
Can you confirm whether this is an Ember Data issue or a PouchDB issue? I.e. could you take a look at the documents in the local PouchDB and see if the deletion really wasn't replicated, or if it's just not being updated in the Ember Data store? |
Please forgive any mishap from my part, I'm very new at this. I've tried to check this with something like this code: temp1.currentModel.store.adapterFor('post').db.allDocs('post', function() {console.log(arguments[1].total_rows)}) and the number of records is correct. Checking the local db (chrome devtools > resources) does seem to mark all the documents as deleted. For some reason the local db is keeping every document revision even from long deleted documents, is there a way to tell PouchDB to cleanup? As well as that previous snippet I showed you, I was calling the refresh method on my route. It does refresh (and I know the route's model method is called) but the deleted documents still show up as well as any model added in the meantime. I'm still new and didn't get the chance to learn but there is a chance that a filtered/query would also not be updated correctly. |
After a bit of debugging it seems that the update() with eventually call the store.pushMany() which only pushes data into the store and never removes items (afaik). |
Aha, so this is an ember-pouch issue. Interesting; I'll see what I can do about fixing the |
Or if you want to tackle this yourself, I happen to be super busy right now, and Ember Data is really new technology, so your guess is probably as good as mine. :) |
I've been trying to figure it out but I must be missing something. In ember-pouch and ember-relational where is the code that directly listens to pouchdb events? I believe what needs to be done is to find the records that were deleted (update must be doing this) and call the transitionTo('deleted.saved') on the record. My investigation tells me that the record itself still responds with false to get('isDeleted') and that's the issue. However, I can't find the places that directly glue pouchdb and the ember integrations. I need to 1) find out to translate a couchdb id into a ember record instance and 2) where the delete should be glued. |
That code is implemented by the user him/herself; it's what I recommend in the README where you listen for live changes: new PouchDB('mydb').changes({
since: 'now',
live: true
}).on('change', function () {
recordArray.update();
}); I forget the exact syntax, but deleted changes are definitely propagated to that changes listener, so you should be able to do something like new PouchDB('mydb').changes({
since: 'now',
live: true
}).on('change', function (change) {
recordArray.update();
if (change.deleted) {
// do something else
}
}); but like I said, I forget the exact syntax. |
Also the folks in the #emberjs channel on Freenode are pretty responsive; we are also in #pouchdb if you want to ask us there |
For now I've settled with the following on the change handler. Somehow I've the feeling that when I have multiple routes and stores this might not work as expected, but at least it works now. |
Yeah, this is not ideal. The relational-pouch should probably offer a changes API that does the string manipulation for you. |
Also we need something better than this |
@nolanlawson I suppose, PouchdbAdapter must listen for updates, if db sync was set up. |
@vectart Yeah, originally I wanted to be agnostic and just hook into PouchDB, regardless of whether it was syncing or not, but it seems like 99% of people want to have a syncing PouchDB, which is understandable. So having an alternative API that handles all that stuff for you would be good. |
Also a lot of people are reporting better results with the nightly than with 3.0.6. We'll release the next version soon. http://pouchtest.com/nightly |
@nolanlawson Sweet, then I'll postpone investigation until the next version is released. |
@vectart I would like the live changes patch to move from my applications to Ember-Pouch. I hope you can find the time. |
OK so we now have a fix for this, which is detailed in the README. It's kind of ugly and I'm not 100% satisfied yet, but at least it fixes the immediate problem. |
Also the relevant fix is this commit: 6f49b13 |
Hi,
I'm rather new to Ember & Pouch but I've setup a small test project where I list a set of items. Everything like adding and updating seems to work but for single problem, if I delete a document (server-side) the changes aren't reflected until I refresh the page.
I've the afterModel function as per the docs implemented and updating a document server side is reflected on the page. I'm unsure about the issue but a potential problem is that every document on my couchdb has the id in the form "post_2_*" where post is my model name and 2 is (for some reason) always the same for every document. The * part does show some sort of unique identifier.
The text was updated successfully, but these errors were encountered: