Skip to content
Browse files

(#642) - Ensure only winningRev is included in leveldb changes

  • Loading branch information...
1 parent 60f3cfa commit 41b7c1b1a2c31ab3cba1979d36c29a5d64e48215 @daleharvey daleharvey committed Mar 29, 2013
Showing with 12 additions and 10 deletions.
  1. +5 −2 src/adapters/pouch.idb.js
  2. +5 −6 src/adapters/pouch.leveldb.js
  3. +2 −2 tests/test.changes.js
View
7 src/adapters/pouch.idb.js
@@ -744,9 +744,11 @@ var IdbPouch = function(opts, callback) {
var cursor = event.target.result;
// Try to pre-emptively dedup to save us a bunch of idb calls
- var changeId = cursor.value._id, changeIdIndex = resultIndices[changeId];
+ var changeId = cursor.value._id;
+ var changeIdIndex = resultIndices[changeId];
if (changeIdIndex !== undefined) {
- results[changeIdIndex].seq = cursor.key; // update so it has the later sequence number
+ results[changeIdIndex].seq = cursor.key;
+ // update so it has the later sequence number
results.push(results[changeIdIndex]);
results[changeIdIndex] = null;
resultIndices[changeId] = results.length - 1;
@@ -776,6 +778,7 @@ var IdbPouch = function(opts, callback) {
changes: changeList,
doc: doc
};
+
if (isDeleted(metadata, mainRev)) {
change.deleted = true;
}
View
11 src/adapters/pouch.leveldb.js
@@ -628,18 +628,17 @@ var LevelPouch = function(opts, callback) {
change.doc._rev = Pouch.merge.winningRev(metadata);
- if (isDeleted(metadata)) {
+ if (isDeleted(metadata)) {
change.deleted = true;
}
if (opts.conflicts) {
change.doc._conflicts = Pouch.merge.collectConflicts(metadata);
}
- // dedupe changes (TODO: more efficient way to accomplish this?)
- results = results.filter(function(doc) {
- return doc.id !== change.id;
- });
- results.push(change);
+ // Ensure duplicated dont overwrite winning rev
+ if (+data.key === metadata.rev_map[change.doc._rev]) {
+ results.push(change);
+ }
});
})
.on('error', function(err) {
View
4 tests/test.changes.js
@@ -320,15 +320,15 @@ adapters.map(function(adapter) {
var localname = this.name, remotename = this.name + "-remote";
initDBPair(localname, remotename, function(localdb, remotedb) {
-
localdb.bulkDocs({docs: docs1}, function(err, info) {
docs2[0]._rev = info[2].rev;
var rev1 = docs2[1]._rev = info[3].rev;
localdb.put(docs2[0], function(err, info) {
localdb.put(docs2[1], function(err, info) {
var rev2 = info.rev;
Pouch.replicate(localdb, remotedb, function(err, done) {
- // update remote once, local twice, then replicate from remote to local so the remote losing conflict is later in the tree
+ // update remote once, local twice, then replicate from
+ // remote to local so the remote losing conflict is later in the tree
localdb.put({_id: "3", _rev: rev2, integer: 20}, function(err, resp) {
var rev3local = resp.rev;
localdb.put({_id: "3", _rev: rev3local, integer: 30}, function(err, resp) {

0 comments on commit 41b7c1b

Please sign in to comment.
Something went wrong with that request. Please try again.