Reduce the number of CouchDB round trips when pushing changes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Bindwood |
Won't Fix
|
Low
|
Unassigned |
Bug Description
In the new synchroniser, we have a list of changed GUIDs. For each one, we:
1. download the current version from CouchDB
2. if the local item has been deleted, send a delete request to CouchDB.
3. otherwise, update the document from local data and save it back to CouchDB if changed.
This leads to two round trips per changed item. We should be able to reduce this to two round trips total:
1. Retrieve the current version of all changed items:
POST /bookmarks/
...
{keys: [item1, item2, ...]}
2. Process each item, based on the documents we've downloaded, and form a list of updated/deleted documents.
3. Push all the changes back to CouchDB in bulk:
POST /bookmarks/
...
{docs: [
{_id: doc1, _rev: ..., ...},
{_id: doc2, _rev: ..., _deleted: true },
...
]}
Will have to work out whether the above is possible with the couch.js interface we're using.
Changed in bindwood: | |
importance: | Undecided → Low |
The couch.js API supports both of these operations:
db.allDocs( {include_ docs: true}, [record_id, ...])
db.bulkSave([doc1, doc2, ..])