feat: paginate recentposts.rss and

category/1/recentposts.rss
isekai-main
Barış Soner Uşaklı 2 years ago
parent 2836be5cfa
commit ebd7c05c4c

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const winston = require('winston');
const _ = require('lodash'); const _ = require('lodash');
const db = require('../database'); const db = require('../database');
@ -11,11 +12,14 @@ const plugins = require('../plugins');
const batch = require('../batch'); const batch = require('../batch');
module.exports = function (Categories) { module.exports = function (Categories) {
Categories.getRecentReplies = async function (cid, uid, count) { Categories.getRecentReplies = async function (cid, uid, start, stop) {
if (!parseInt(count, 10)) { // backwards compatibility, treat start as count
return []; 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); pids = await privileges.posts.filter('topics:read', pids, uid);
return await posts.getPostSummaryByPids(pids, uid, { stripTags: true }); return await posts.getPostSummaryByPids(pids, uid, { stripTags: true });
}; };

@ -307,7 +307,11 @@ async function generateForRecentPosts(req, res, next) {
if (meta.config['feeds:disableRSS']) { if (meta.config['feeds:disableRSS']) {
return next(); 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({ const feed = generateForPostsFeed({
title: 'Recent Posts', title: 'Recent Posts',
description: 'A list of recent posts', description: 'A list of recent posts',
@ -323,11 +327,14 @@ async function generateForCategoryRecentPosts(req, res) {
return controllers404.handle404(req, res); return controllers404.handle404(req, res);
} }
const cid = req.params.category_id; 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([ const [userPrivileges, category, postData] = await Promise.all([
privileges.categories.get(cid, req.uid), privileges.categories.get(cid, req.uid),
categories.getCategoryData(cid), 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) { if (!category) {

@ -10,7 +10,7 @@ const SocketCategories = module.exports;
require('./categories/search')(SocketCategories); require('./categories/search')(SocketCategories);
SocketCategories.getRecentReplies = async function (socket, cid) { 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) { SocketCategories.get = async function (socket) {

Loading…
Cancel
Save