janmonschke / backbone-couchdb

A couchdb connector for backbone with support for real time changes.

Home Page:http://janmonschke.com/projects/backbone-couchdb.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create() in _changes function?

sgmentzer opened this issue · comments

The _changes() function of the connector calls coll.create(doc), which according to the Backbone API both creates the model on the server and adds it to the collection. But by definition any model in the Couchdb changes feed already exists on the server, so shouldn't it be just coll.add(doc)?

You're probably right. Did you try out how it worked when changing it to .add()? Shame on me that there are no tests ;)

The create() causes a document update cascade, resulting in multiple unnecessary document revisions. I found this by watching the Couchdb server log while testing an app. It often causes a 409 document conflict error. You can see this yourself if you run three clients of your Comment app. Save a comment in one and watch the server log, or notice that the comment document revision count increments.

I changed it to add() and that resolved everything.

By the way, thanks for the project. It saved me quite a bit of time!

Since you found this "bug" feel free to send a pull request and I'll merge it into the master.