From aa0fcea0017aa7a065c9160418cf8f8aa4ceb3d3 Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Fri, 1 Apr 2022 21:28:53 +0200 Subject: [PATCH 1/2] Improve performance of query when seq is far behind log --- index.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e02983d..0af5c45 100644 --- a/index.js +++ b/index.js @@ -1092,9 +1092,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) @@ -1117,6 +1114,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) => { diff --git a/package.json b/package.json index b48fd15..0da0ea3 100644 --- a/package.json +++ b/package.json @@ -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": { From d58009d4169d8c98e5f4736af36c4be3188f0587 Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Sat, 2 Apr 2022 19:05:31 +0200 Subject: [PATCH 2/2] Make sure multicb done() is only called once --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0af5c45..11574f8 100644 --- a/index.js +++ b/index.js @@ -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)