-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update members tangle calculation for exclusion spec #75
Conversation
Was first thinking I could get the epoch by getting the latest epoch tangle and using the |
Hmm I can't just get my own feed with the secret as the purpose though since someone else might've been the creator of the epoch init. |
Tested performance using the With group, and epoch tangles:
With group, epoch, and members tangles:
|
With only the group tangle it was
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good. All my comments are suggestions/ optimisations (no 🔥 i.e. must change)
Nice one
function addSomeTangles(content, tangles, cb) { | ||
if (tangles.length === 0) return cb(null, content) | ||
|
||
const currTangle = tangles[0] | ||
|
||
getTangle[currTangle](content.recps[0], (err, generatedTangle) => { | ||
getTangle(server, currTangle, content.recps[0], (err, generatedTangle) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to get group tangle when adding group tangle to message')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (err) return cb(clarify(err, 'Failed to get group tangle when adding group tangle to message')) | |
if (err) return cb(clarify(err, `Failed to get ${currTangle} tangle when adding group tangle to message`)) |
addSomeTangles(content, tangles, (err, content) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'failed to add tangles to content')) | ||
addSomeTangles(content, tangles, (err, content) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sufficient:
addSomeTangles(content, tangles, cb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but I wanted more clarify
since this gets run a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And new Error('CLARIFICATION', {cause: err})
is the new clarify(err, 'CLARIFICATION')
pull.map((feed) => | ||
pull( | ||
server.db.query(where(author(feed.id)), toPullStream()), | ||
// get all first messages, since that's where the init would be | ||
pull.take(1) | ||
) | ||
), | ||
pull.flatten(), | ||
// find the init | ||
pull.filter((msg) => msg.value?.content?.type === 'group/init'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pull.map((feed) => | |
pull( | |
server.db.query(where(author(feed.id)), toPullStream()), | |
// get all first messages, since that's where the init would be | |
pull.take(1) | |
) | |
), | |
pull.flatten(), | |
// find the init | |
pull.filter((msg) => msg.value?.content?.type === 'group/init'), | |
pull.map((feed) => | |
pull( | |
server.db.query( | |
where(and(author(feed.id), type('group/init'))), | |
toPullStream() | |
), | |
pull.filter(isInit) | |
pull.take(1) | |
) | |
), | |
pull.flatten(), |
will require type
and isInit
to be imported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is faster because we already have an index on type
if (tangle === 'members') { | ||
// we find the id of the init msg for the current epoch | ||
pull( | ||
server.metafeeds.branchStream({ old: true, live: false }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: does this return all feeds or just your meta-feed feeds? (I can't remember and the docs don't say!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to specify opts.root
to only get from one person
// prettier-ignore | ||
return cb(new Error(`get-tangle expects valid groupId, got: ${groupId}`)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ssb-tribes
I put a cache over the groups tangle https://github.com/ssbc/ssb-tribes/blob/master/lib/get-group-tangle.js#L12
I will perhaps look at adding that in another PR in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jitdb cache seems really fast after the first query
const { where, and, toPullStream } = ssb.db.operators | ||
pull( | ||
ssb.db.query(where(and(tangleRoot(root))), toPullStream()), | ||
pull.collect(cb) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { where, and, toPullStream } = ssb.db.operators | |
pull( | |
ssb.db.query(where(and(tangleRoot(root))), toPullStream()), | |
pull.collect(cb) | |
) | |
const { where, toCallback } = ssb.db.operators | |
ssb.db.query(where(tangleRoot(root)), toCallback(cb)) |
|
||
//console.time('getTangles') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//console.time('getTangles') |
@@ -129,6 +140,8 @@ test(`get-tangle-${n}-publishes`, (t) => { | |||
(err) => { | |||
t.error(err, 'no error publishing') | |||
|
|||
//console.timeEnd('getTangles') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//console.timeEnd('getTangles') |
Fixes #69
Based on #65