mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-18 18:40:58 +01:00
fix: #14071, duplicate items loaded via IS on /world
This commit is contained in:
@@ -84,12 +84,13 @@ define('forum/world', [
|
||||
}
|
||||
|
||||
const afterEl = direction > 0 ? posts.pop() : posts.shift();
|
||||
const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||
if (after < config.topicsPerPage) {
|
||||
const index = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||
const after = afterEl.getAttribute('data-tid');
|
||||
if (index < config.topicsPerPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadTopicsAfter(after, direction, (payload, callback) => {
|
||||
loadTopicsAfter(index, after, direction, (payload, callback) => {
|
||||
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
||||
const listEl = document.getElementById('world-feed');
|
||||
$(listEl)[direction === -1 ? 'prepend' : 'append'](html);
|
||||
@@ -114,10 +115,11 @@ define('forum/world', [
|
||||
return Math.floor(after / config.topicsPerPage) + (direction > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
function loadTopicsAfter(after, direction, callback) {
|
||||
function loadTopicsAfter(index, after, direction, callback) {
|
||||
callback = callback || function () {};
|
||||
const query = utils.params();
|
||||
query.page = calculateNextPage(after, direction);
|
||||
query.page = calculateNextPage(index, direction);
|
||||
query.after = after;
|
||||
infinitescroll.loadMoreXhr(query, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user