From b415e82d715287a48617deafbf2edff6d9ca48f1 Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Thu, 20 Apr 2017 22:01:11 +0200 Subject: [PATCH] Only show the first 100 messages to minimize load of user feed --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index b0d09d0..a08f680 100644 --- a/index.js +++ b/index.js @@ -178,6 +178,16 @@ exports.init = function (sbot, config) { ) } + function take (n) { + return function (read) { + return function (abort, cb) { + //after n reads, tell the source to abort! + if(!n--) return read(true, cb) + read(null, cb) + } + } + } + function serveFeeds(req, res, following, channelSubscriptions, feedId) { var opts = defaultOpts @@ -201,6 +211,7 @@ exports.init = function (sbot, config) { (msg.value.author in following || msg.value.content.channel in channelSubscriptions) }), + take(100), pull.collect(function (err, logs) { if (err) return respond(res, 500, err.stack || err) res.writeHead(200, {