Permalink
Browse files

Wait until we have dedupped the changes feed before emitting changes

  • Loading branch information...
1 parent d3495c0 commit b5d0bf77c65c92a63d8e496a2da166df08c06aa9 @daleharvey daleharvey committed Apr 23, 2012
Showing with 35 additions and 1 deletion.
  1. +9 −1 src/adapters/pouch.idb.js
  2. +26 −0 tests/test.replication.js
View
@@ -172,6 +172,9 @@ var IdbPouch = function(opts, callback) {
results.forEach(function(result) {
delete result._bulk_seq;
+ if (/_local/.test(result.id)) {
+ return;
+ }
api.changes.emit(result);
});
call(callback, null, results);
@@ -540,12 +543,18 @@ var IdbPouch = function(opts, callback) {
if (opts.continuous) {
api.changes.addListener(opts.onChange);
}
+ results.map(function(c) {
+ call(opts.onChange, c);
+ });
return call(opts.complete, null, {results: results});
}
var cursor = event.target.result;
var index = transaction.objectStore(DOC_STORE);
index.get(cursor.value._id).onsuccess = function(event) {
var doc = event.target.result;
+ if (/_local/.test(doc.id)) {
+ return cursor['continue']();
+ }
var c = {
id: doc.id,
seq: cursor.key,
@@ -566,7 +575,6 @@ var IdbPouch = function(opts, callback) {
return doc.id !== c.id;
});
results.push(c);
- call(opts.onChange, c);
cursor['continue']();
};
};
View
@@ -114,6 +114,32 @@ asyncTest("Test checkpoint 2", function() {
});
});
+asyncTest("Test checkpoint 3 :)", function() {
+ var self = this;
+ var doc = {_id: "3", count: 0};
+ initDBPair(this.name, this.remote, function(db, remote) {
+ db.put(doc, {}, function(err, results) {
+ Pouch.replicate(db, remote, function(err, result) {
+ ok(result.ok, 'replication was ok');
+ doc._rev = results.rev;
+ doc.count++;
+ db.put(doc, {}, function(err, results) {
+ doc._rev = results.rev;
+ doc.count++;
+ db.put(doc, {}, function(err, results) {
+ Pouch.replicate(db, remote, function(err, result) {
+ ok(result.ok, 'replication was ok');
+ ok(result.docs_written === 1, 'correct # docs written');
+ start();
+ });
+ });
+ });
+ });
+ });
+ });
+});
+
+
// CouchDB will not generate a conflict here, it uses a deteministic
// method to generate the revision number, however we cannot copy its
// method as it depends on erlangs internal data representation

0 comments on commit b5d0bf7

Please sign in to comment.