fix: #14071, duplicate items loaded via IS on /world

This commit is contained in:
Julian Lam
2026-03-09 12:47:04 -04:00
parent 215d64408c
commit d29f1fbdf8
2 changed files with 25 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
const _ = require('lodash');
const db = require('../../database');
const meta = require('../../meta');
const user = require('../../user');
const topics = require('../../topics');
@@ -17,9 +18,10 @@ const controller = module.exports;
controller.list = async function (req, res) {
const { topicsPerPage } = await user.getSettings(req.uid);
const page = parseInt(req.query.page, 10) || 1;
const start = Math.max(0, (page - 1) * topicsPerPage);
const stop = start + topicsPerPage - 1;
let { page, after } = req.query;
page = parseInt(page, 10) || 1;
let start = Math.max(0, (page - 1) * topicsPerPage);
let stop = start + topicsPerPage - 1;
const [userSettings, userPrivileges] = await Promise.all([
user.getSettings(req.uid),
@@ -31,6 +33,7 @@ controller.list = async function (req, res) {
cid: '-1',
start: start,
stop: stop,
after,
sort: req.query.sort,
settings: userSettings,
query: req.query,
@@ -55,7 +58,18 @@ controller.list = async function (req, res) {
({ tids, topicCount } = await topics.getSortedTopics(cidQuery));
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
} else {
tids = await categories.getTopicIds(cidQuery);
if (after) {
// Update start/stop with values inferred from `after`
const set = await categories.buildTopicsSortedSet(cidQuery);
const index = await db.sortedSetRevRank(set, decodeURIComponent(after));
if (index && start - index < 1) {
const count = stop - start;
start = index + 1;
stop = start + count;
}
}
tids = await categories.getTopicIds({ ...cidQuery, start, stop });
topicCount = await categories.getTopicCount(cidQuery);
}
data.topicCount = topicCount;