Skip to content

Commit 2baa95c

Browse files
committed
(#6055) - remove docCount optimization from IDB
1 parent 4bf2712 commit 2baa95c

File tree

7 files changed

+130
-88
lines changed

7 files changed

+130
-88
lines changed

packages/node_modules/pouchdb-adapter-idb/src/allDocs.js

Lines changed: 25 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node_modules/pouchdb-adapter-idb/src/countDocs.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node_modules/pouchdb-adapter-idb/src/index.js

Lines changed: 14 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/browser.worker.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,25 @@ if (typeof window.Worker === 'function' &&
2424

2525
function runTests() {
2626

27+
var worker;
28+
29+
before(function () {
30+
worker = new Worker('worker.js');
31+
worker.postMessage(['source', sourceFile]);
32+
});
33+
34+
after(function () {
35+
worker.terminate();
36+
});
37+
2738
function workerPromise(message) {
2839
return new Promise(function (resolve, reject) {
29-
var worker = new Worker('worker.js');
30-
worker.addEventListener('error', function (e) {
31-
worker.terminate();
40+
worker.onerror = function (e) {
3241
reject(new Error(e.message + ": " + e.filename + ': ' + e.lineno));
33-
});
34-
worker.addEventListener('message', function (e) {
35-
worker.terminate();
42+
};
43+
worker.onmessage = function (e) {
3644
resolve(e.data);
37-
});
38-
worker.postMessage(['source', sourceFile]);
45+
};
3946
worker.postMessage(message);
4047
});
4148
}
@@ -79,7 +86,7 @@ function runTests() {
7986
});
8087

8188
it('add doc with blob attachment', function () {
82-
return workerPromise(['allDocs', dbs.name]).then(function (data) {
89+
return workerPromise(['postAttachmentThenAllDocs', dbs.name]).then(function (data) {
8390
data.title.should.equal('lalaa');
8491
});
8592
});
@@ -93,5 +100,31 @@ function runTests() {
93100
blob.size.should.equal(6);
94101
});
95102
});
103+
104+
it('total_rows consistent between worker and main thread', function () {
105+
var db = new PouchDB(dbs.name);
106+
// both threads agree the count is 0
107+
return testUtils.Promise.all([
108+
db.allDocs().then(function (res) {
109+
res.total_rows.should.equal(0);
110+
}),
111+
workerPromise(['allDocs', dbs.name]).then(function (res) {
112+
res.total_rows.should.equal(0);
113+
})
114+
]).then(function () {
115+
// post a doc
116+
return db.post({});
117+
}).then(function () {
118+
// both threads agree the count is 1
119+
return testUtils.Promise.all([
120+
db.allDocs().then(function (res) {
121+
res.total_rows.should.equal(1);
122+
}),
123+
workerPromise(['allDocs', dbs.name]).then(function (res) {
124+
res.total_rows.should.equal(1);
125+
})
126+
]);
127+
});
128+
});
96129
});
97130
}

tests/integration/test.basics.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,33 @@ adapters.forEach(function (adapter) {
10621062
});
10631063
});
10641064

1065+
it('test info() after db close', function () {
1066+
var db = new PouchDB(dbs.name);
1067+
return db.close().then(function () {
1068+
return db.info().catch(function (err) {
1069+
err.message.should.equal('database is closed');
1070+
});
1071+
});
1072+
});
1073+
1074+
it('test get() after db close', function () {
1075+
var db = new PouchDB(dbs.name);
1076+
return db.close().then(function () {
1077+
return db.get('foo').catch(function (err) {
1078+
err.message.should.equal('database is closed');
1079+
});
1080+
});
1081+
});
1082+
1083+
it('test close() after db close', function () {
1084+
var db = new PouchDB(dbs.name);
1085+
return db.close().then(function () {
1086+
return db.close().catch(function (err) {
1087+
err.message.should.equal('database is closed');
1088+
});
1089+
});
1090+
});
1091+
10651092
if (adapter === 'local') {
10661093
// TODO: this test fails in the http adapter in Chrome
10671094
it('should allow unicode doc ids', function (done) {

0 commit comments

Comments
 (0)