Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle overlapping keyranges (fixes #48)

  • Loading branch information...
commit 9bf2e2aeef5e49285540b7d04c0d1c11a21efe35 1 parent bfc4d84
@daleharvey daleharvey authored
Showing with 30 additions and 4 deletions.
  1. +10 −4 src/adapters/pouch.idb.js
  2. +20 −0 tests/test.basics.js
View
14 src/adapters/pouch.idb.js
@@ -300,11 +300,17 @@ var IdbPouch = function(opts, callback) {
cursReq.onsuccess = function(event) {
var cursor = event.target.result;
- if (cursor) {
+ if (cursor && buckets.length) {
var bucket = buckets.shift();
- update(cursor, cursor.value, bucket[0], function() {
- markConflicts(bucket);
- });
+ if (cursor.key === bucket[0].metadata.id) {
+ update(cursor, cursor.value, bucket[0], function() {
+ markConflicts(bucket);
+ });
+ } else {
+ insert(bucket[0], function() {
+ markConflicts(bucket);
+ });
+ }
} else {
// Cursor has exceeded the key range so the rest are inserts
buckets.forEach(function(bucket) {
View
20 tests/test.basics.js
@@ -172,3 +172,23 @@ asyncTest("Testing Rev format", function() {
});
});
+asyncTest("Testing issue #48", function() {
+
+ var docs = [{"id":"0"}, {"id":"1"}, {"id":"2"}, {"id":"3"}, {"id":"4"}, {"id":"5"}];
+ var x = 0;
+ var timer;
+
+ initTestDB(this.name, function(err, db) {
+ var save = function() {
+ db.bulkDocs({docs: docs}, function(err, res) {
+ if (++x === 10) {
+ ok(true, 'all updated succedded');
+ clearInterval(timer);
+ start();
+ }
+ });
+ };
+ timer = setInterval(save, 500);
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.