From 29f56c3e49c767f75164f57ccd1ac52b389794c0 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 9 May 2017 14:49:03 -1000 Subject: Optimize looking up follow --- lib/app.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/app.js') 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) + }) ) } -- cgit v1.2.3