diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-09 14:49:03 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-09 19:44:37 -1000 |
commit | 29f56c3e49c767f75164f57ccd1ac52b389794c0 (patch) | |
tree | d8efaf2a5de70208d8f24ad3940ad82f38d01402 | |
parent | 11e894c5c9efbc6ee141f614eea3a328517aee5b (diff) | |
download | patchfoo-29f56c3e49c767f75164f57ccd1ac52b389794c0.tar.gz patchfoo-29f56c3e49c767f75164f57ccd1ac52b389794c0.zip |
Optimize looking up follow
-rw-r--r-- | lib/app.js | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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) + }) ) } |