From b49af0a135fc4f332a8e4893806f98e6aa90d0fe Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 21 Nov 2016 13:49:36 +0300 Subject: [PATCH] #5223 adjust pagination so each page shows `postsPerPage` posts --- src/controllers/topics.js | 2 +- src/topics.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/topics.js b/src/controllers/topics.js index e6072be9f2..20c2b87cbd 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -66,7 +66,7 @@ topicsController.get = function (req, res, callback) { settings = results.settings; var postCount = parseInt(results.topic.postcount, 10); - pageCount = Math.max(1, Math.ceil((postCount - 1) / settings.postsPerPage)); + pageCount = Math.max(1, Math.ceil(postCount / settings.postsPerPage)); if (utils.isNumber(req.params.post_index) && (req.params.post_index < 1 || req.params.post_index > postCount)) { return helpers.redirect(res, '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : '')); diff --git a/src/topics.js b/src/topics.js index de8b795466..71e103d0aa 100644 --- a/src/topics.js +++ b/src/topics.js @@ -234,6 +234,10 @@ var social = require('./social'); function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) { async.waterfall([ function (next) { + if (start > 0 && stop > 0) { + start--; + stop--; + } posts.getPidsFromSet(set, start, stop, reverse, next); }, function (pids, next) { @@ -243,6 +247,7 @@ var social = require('./social'); if (topic.mainPid && start === 0) { pids.unshift(topic.mainPid); + pids.pop(); } posts.getPostsByPids(pids, uid, next); },