Skip to content

Commit

Permalink
ignore DEFERRED ops in prepare() (#241)
Browse files Browse the repository at this point in the history
* execute DEFERRED ops in prepare()

* actually we should just ignore DEFERRED

* tweak
  • Loading branch information
staltz authored Jan 30, 2023
1 parent 3bb1da7 commit a64d45a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,11 @@ module.exports = function (log, indexesPath) {
} else if (!op.type) {
// to support `query(fromDB(jitdb), toCallback(cb))`
getFullBitset(cb)
} else console.error('Unknown type', op)
} else if (op.type === 'DEFERRED') {
// DEFERRED only appears in this pipeline when using `prepare()` API,
// and only updateIndexes() is the important part in `prepare()`.
cb(new TypedFastBitSet())
} else console.error('Unknown type in jitdb executeOperation:', op)
}

function forEachLeafOperationIn(operation, fn) {
Expand All @@ -1014,7 +1018,8 @@ module.exports = function (log, indexesPath) {
op.type === 'LTE' ||
op.type === 'GT' ||
op.type === 'GTE' ||
!op.type // e.g. query(fromDB, toCallback), or empty deferred()
op.type === 'DEFERRED' ||
!op.type // e.g. query(fromDB, toCallback), or empty deferred() result
);
else debug('Unknown operator type: ' + op.type)
})
Expand Down
15 changes: 15 additions & 0 deletions test/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,18 @@ prepareAndRunTest('prepare an index', dir, (t, db, raf) => {
})
)
})

prepareAndRunTest('prepare a DEFERRED operation', dir, (t, db, raf) => {
const deferredQuery = {
type: 'DEFERRED',
task: (meta, cb) => {
cb()
},
}

db.prepare(deferredQuery, (err, duration) => {
t.error(err, 'no error')
t.equals(typeof duration, 'number')
t.end()
})
})

0 comments on commit a64d45a

Please sign in to comment.