Skip to content

Commit a64d45a

Browse files
authored
ignore DEFERRED ops in prepare() (#241)
* execute DEFERRED ops in prepare() * actually we should just ignore DEFERRED * tweak
1 parent 3bb1da7 commit a64d45a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,11 @@ module.exports = function (log, indexesPath) {
991991
} else if (!op.type) {
992992
// to support `query(fromDB(jitdb), toCallback(cb))`
993993
getFullBitset(cb)
994-
} else console.error('Unknown type', op)
994+
} else if (op.type === 'DEFERRED') {
995+
// DEFERRED only appears in this pipeline when using `prepare()` API,
996+
// and only updateIndexes() is the important part in `prepare()`.
997+
cb(new TypedFastBitSet())
998+
} else console.error('Unknown type in jitdb executeOperation:', op)
995999
}
9961000

9971001
function forEachLeafOperationIn(operation, fn) {
@@ -1014,7 +1018,8 @@ module.exports = function (log, indexesPath) {
10141018
op.type === 'LTE' ||
10151019
op.type === 'GT' ||
10161020
op.type === 'GTE' ||
1017-
!op.type // e.g. query(fromDB, toCallback), or empty deferred()
1021+
op.type === 'DEFERRED' ||
1022+
!op.type // e.g. query(fromDB, toCallback), or empty deferred() result
10181023
);
10191024
else debug('Unknown operator type: ' + op.type)
10201025
})

test/add.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,18 @@ prepareAndRunTest('prepare an index', dir, (t, db, raf) => {
420420
})
421421
)
422422
})
423+
424+
prepareAndRunTest('prepare a DEFERRED operation', dir, (t, db, raf) => {
425+
const deferredQuery = {
426+
type: 'DEFERRED',
427+
task: (meta, cb) => {
428+
cb()
429+
},
430+
}
431+
432+
db.prepare(deferredQuery, (err, duration) => {
433+
t.error(err, 'no error')
434+
t.equals(typeof duration, 'number')
435+
t.end()
436+
})
437+
})

0 commit comments

Comments
 (0)