Skip to content

Commit

Permalink
Merge pull request #206 from ssb-ngi-pointer/faster-empty-db-query
Browse files Browse the repository at this point in the history
Improve performance of query when seq is far behind log
  • Loading branch information
arj03 authored Apr 4, 2022
2 parents 19675f7 + d58009d commit 6d62f3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,14 @@ module.exports = function (log, indexesPath) {
const index = newIndexes[indexName]
if (doneIndexing) indexes[indexName] = index
index.offset = offset
done(() => {
saveIndex(indexName, index, count)
})
}

done(() => {
for (var indexName in newIndexes) {
const index = newIndexes[indexName]
saveIndex(indexName, index, count)
}
})
}

const logstreamId = Math.ceil(Math.random() * 1000)
Expand Down Expand Up @@ -1092,9 +1096,6 @@ module.exports = function (log, indexesPath) {
// kick-start this chain with a dummy null value
push.values([null]),

// ensure that the seq->offset index is synchronized with the log
push.asyncMap((_, next) => ensureSeqIndexSync(next)),

// load lazy indexes, if any
push.asyncMap((_, next) => {
const lazyIdxNames = detectLazyIndexesUsed(operation)
Expand All @@ -1117,6 +1118,9 @@ module.exports = function (log, indexesPath) {
createIndexes(opsMissingIdx, next)
}),

// ensure that the seq->offset index is synchronized with the log
push.asyncMap((_, next) => ensureSeqIndexSync(next)),

// get bitset for the input operation, and cache it
push.asyncMap((_, next) => {
getBitsetForOperation(operation, (bitset, filters) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"ssb-keys": "^8.1.0",
"ssb-ref": "^2.14.3",
"ssb-validate": "^4.1.1",
"tap-arc": "^0.3.4",
"tap-bail": "^1.0.0",
"tap-arc": "^0.1.2",
"tape": "^5.2.2"
},
"scripts": {
Expand Down

0 comments on commit 6d62f3a

Please sign in to comment.