From 8c420a8d3bd2ae01b8ecb8409e951c5fde1e0f8d Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Sat, 20 May 2017 21:37:25 +0200 Subject: [PATCH] Limit channel & feed serving by default --- index.js | 16 +++++++++++----- render.js | 8 ++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 61f98ab..5b00d6c 100644 --- a/index.js +++ b/index.js @@ -93,11 +93,14 @@ exports.init = function (sbot, config) { function serveFeed(req, res, feedId) { console.log("serving feed: " + feedId) + var showAll = req.url.endsWith("?showAll") + var showAllHTML = showAll ? '' : '
Show whole feed' + getAbout(feedId, function (err, about) { - if (err) return respond(res, 500, err.stack || err) + if (err) return respond(res, 500, err.stack || err) pull( - sbot.createUserStream({ id: feedId, reverse: true }), + sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : 10 }), pull.collect(function (err, logs) { if (err) return respond(res, 500, err.stack || err) res.writeHead(200, { @@ -109,7 +112,7 @@ exports.init = function (sbot, config) { paramap(addFollowAbout, 8), paramap(addVoteMessage, 8), paramap(addGitLinks, 8), - pull(renderAbout(defaultOpts, about), wrapPage(about.name)), + pull(renderAbout(defaultOpts, about, showAllHTML), wrapPage(about.name)), toPull(res, function (err) { if (err) console.error('[viewer]', err) }) @@ -191,9 +194,12 @@ exports.init = function (sbot, config) { function serveChannel(req, res, url) { var channelId = url.substring(url.lastIndexOf('channel/')+8, 100) console.log("serving channel: " + channelId) + + var showAll = req.url.endsWith("?showAll") + var showAllHTML = showAll ? '' : '
Show whole feed' pull( - sbot.query.read({ limit: 500, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), + sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), pull.collect(function (err, logs) { if (err) return respond(res, 500, err.stack || err) res.writeHead(200, { @@ -203,7 +209,7 @@ exports.init = function (sbot, config) { pull.values(logs), paramap(addAuthorAbout, 8), paramap(addVoteMessage, 8), - pull(renderThread(defaultOpts), wrapPage('#' + channelId)), + pull(renderThread(defaultOpts, showAllHTML), wrapPage('#' + channelId)), toPull(res, function (err) { if (err) console.error('[viewer]', err) }) diff --git a/render.js b/render.js index 625e068..0ffedff 100644 --- a/render.js +++ b/render.js @@ -95,7 +95,7 @@ function wrap(before, after) { }; } -function renderAbout(opts, about) { +function renderAbout(opts, about, showAllHTML = "") { return pull( pull.map(renderMsg.bind(this, opts)), wrap( @@ -111,7 +111,7 @@ function renderAbout(opts, about) { marked(about.description, opts.marked) : '') + '', - '' + + showAllHTML + '' + '' + 'Join Scuttlebutt now' + '' @@ -119,7 +119,7 @@ function renderAbout(opts, about) { ); } -function renderThread(opts) { +function renderThread(opts, showAllHTML = "") { return pull( pull.map(renderMsg.bind(this, opts)), wrap( @@ -128,7 +128,7 @@ function renderThread(opts) { '' + '
', - '
' + + showAllHTML + '' + '' + 'Join Scuttlebutt now' + ''