aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-09 14:49:03 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-09 19:44:37 -1000
commit29f56c3e49c767f75164f57ccd1ac52b389794c0 (patch)
treed8efaf2a5de70208d8f24ad3940ad82f38d01402
parent11e894c5c9efbc6ee141f614eea3a328517aee5b (diff)
downloadpatchfoo-29f56c3e49c767f75164f57ccd1ac52b389794c0.tar.gz
patchfoo-29f56c3e49c767f75164f57ccd1ac52b389794c0.zip
Optimize looking up follow
-rw-r--r--lib/app.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/app.js b/lib/app.js
index 8a74dbb..b57e5a6 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -250,15 +250,17 @@ App.prototype.streamPeers = function (opts) {
App.prototype.getFollow = function (source, dest, cb) {
var self = this
pull(
- self.sbot.links({source: source, dest: dest, rel: 'contact', values: true}),
- pull.filter(function (msg) {
- var c = msg && msg.value && msg.value.content
+ self.sbot.links({source: source, dest: dest, rel: 'contact', reverse: true,
+ values: true, meta: false, keys: false}),
+ pull.filter(function (value) {
+ var c = value && value.content
return c && c.type === 'contact'
}),
- pull.reduce(function (doesFollow, msg) {
- var c = msg.value.content
- return !!c.following
- }, false, cb)
+ pull.take(1),
+ pull.collect(function (err, msgs) {
+ if (err) return cb(err)
+ cb(null, msgs[0] && !!msgs[0].content.following)
+ })
)
}