Skip to content

Commit

Permalink
Use slowEqual to speed up root msg get
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Oct 23, 2023
1 parent 4a4387e commit 1d3a762
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/epochs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

const { promisify: p } = require('util')
const { fromMessageSigil } = require('ssb-uri2')
const { fromMessageSigil, toMessageSigil } = require('ssb-uri2')
const pull = require('pull-stream')
const pullDefer = require('pull-defer')
const pullFlatMerge = require('pull-flat-merge')
Expand Down Expand Up @@ -36,6 +36,7 @@ const isSubsetOf = require('set.prototype.issubsetof')
const { groupRecp } = require('./operators')
const getTangleUpdates = require('./tangles/get-tangle-updates')
const pullMany = require('pull-many')
const { slowEqual } = require('jitdb/operators')

const msgPattern = toPattern(new Butt64('ssb:message/[a-zA-Z0-9-]+/', null, 32))
const feedPattern = toPattern(new Butt64('ssb:feed/[a-zA-Z0-9-]+/', null, 32))
Expand Down Expand Up @@ -521,18 +522,26 @@ function epochNodeStream(ssb, groupId, opts = {}) {
}

function getRootVal(ssb, msgId, cb) {
//console.log('msgId', msgId)
pull(
pullMany([
ssb.db.query(
// TODO: optimize with an equal() op or something
where(isDecrypted('box2')),
where(
and(
isDecrypted('box2'),
slowEqual('key', toMessageSigil(msgId), { prefix: true })
)
),
live({ old: true }),
toPullStream()
),
ssb.db.reindexed(),
pull(
ssb.db.reindexed(),
pull.filter((msg) => fromMessageSigil(msg.key) === msgId)
),
]),
//pull.through((msg) => console.log('about to filter', msg)),
pull.filter((msg) => fromMessageSigil(msg.key) === msgId),
//pull.filter((msg) => fromMessageSigil(msg.key) === msgId),
pull.take(1),
pull.drain(
(msg) => cb(null, msg.value),
Expand Down

0 comments on commit 1d3a762

Please sign in to comment.