Skip to content

Node.js based forum software built for the modern web

feat: paginate recentposts.rss and

Barış Soner Uşaklıebd7c05c4cc1
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index 0e5618b4fe..c7ab8e2fa7 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -1,6 +1,7 @@
'use strict';
+const winston = require('winston');
const _ = require('lodash');
const db = require('../database');
@@ -11,11 +12,14 @@ const plugins = require('../plugins');
const batch = require('../batch');
module.exports = function (Categories) {
- Categories.getRecentReplies = async function (cid, uid, count) {
- if (!parseInt(count, 10)) {
- return [];
+ Categories.getRecentReplies = async function (cid, uid, start, stop) {
+ // backwards compatibility, treat start as count
+ if (stop === undefined && start > 0) {
+ winston.warn('[Categories.getRecentReplies] 3 params deprecated please use Categories.getRecentReplies(cid, uid, start, stop)');
+ stop = start - 1;
+ start = 0;
}
- let pids = await db.getSortedSetRevRange(`cid:${cid}:pids`, 0, count - 1);
+ let pids = await db.getSortedSetRevRange(`cid:${cid}:pids`, start, stop);
pids = await privileges.posts.filter('topics:read', pids, uid);
return await posts.getPostSummaryByPids(pids, uid, { stripTags: true });
};
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index c3bda30473..fbd8de7072 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -307,7 +307,11 @@ async function generateForRecentPosts(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return next();
}
- const postData = await posts.getRecentPosts(req.uid, 0, 19, 'month');
+ const page = parseInt(req.query.page, 10) || 1;
+ const postsPerPage = 20;
+ const start = Math.max(0, (page - 1) * postsPerPage);
+ const stop = start + postsPerPage - 1;
+ const postData = await posts.getRecentPosts(req.uid, start, stop, 'month');
const feed = generateForPostsFeed({
title: 'Recent Posts',
description: 'A list of recent posts',
@@ -323,11 +327,14 @@ async function generateForCategoryRecentPosts(req, res) {
return controllers404.handle404(req, res);
}
const cid = req.params.category_id;
-
+ const page = parseInt(req.query.page, 10) || 1;
+ const topicsPerPage = 20;
+ const start = Math.max(0, (page - 1) * topicsPerPage);
+ const stop = start + topicsPerPage - 1;
const [userPrivileges, category, postData] = await Promise.all([
privileges.categories.get(cid, req.uid),
categories.getCategoryData(cid),
- categories.getRecentReplies(cid, req.uid || req.query.uid || 0, 20),
+ categories.getRecentReplies(cid, req.uid || req.query.uid || 0, start, stop),
]);
if (!category) {
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js
index ad72658f70..0a90698115 100644
--- a/src/socket.io/categories.js
+++ b/src/socket.io/categories.js
@@ -10,7 +10,7 @@ const SocketCategories = module.exports;
require('./categories/search')(SocketCategories);
SocketCategories.getRecentReplies = async function (socket, cid) {
- return await categories.getRecentReplies(cid, socket.uid, 4);
+ return await categories.getRecentReplies(cid, socket.uid, 0, 4);
};
SocketCategories.get = async function (socket) {