mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 13:57:24 +02: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 afterEl = direction > 0 ? posts.pop() : posts.shift();
|
||||||
const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
const index = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||||
if (after < config.topicsPerPage) {
|
const after = afterEl.getAttribute('data-tid');
|
||||||
|
if (index < config.topicsPerPage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTopicsAfter(after, direction, (payload, callback) => {
|
loadTopicsAfter(index, after, direction, (payload, callback) => {
|
||||||
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
||||||
const listEl = document.getElementById('world-feed');
|
const listEl = document.getElementById('world-feed');
|
||||||
$(listEl)[direction === -1 ? 'prepend' : 'append'](html);
|
$(listEl)[direction === -1 ? 'prepend' : 'append'](html);
|
||||||
@@ -114,10 +115,11 @@ define('forum/world', [
|
|||||||
return Math.floor(after / config.topicsPerPage) + (direction > 0 ? 1 : 0);
|
return Math.floor(after / config.topicsPerPage) + (direction > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTopicsAfter(after, direction, callback) {
|
function loadTopicsAfter(index, after, direction, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
const query = utils.params();
|
const query = utils.params();
|
||||||
query.page = calculateNextPage(after, direction);
|
query.page = calculateNextPage(index, direction);
|
||||||
|
query.after = after;
|
||||||
infinitescroll.loadMoreXhr(query, callback);
|
infinitescroll.loadMoreXhr(query, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const db = require('../../database');
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
const user = require('../../user');
|
const user = require('../../user');
|
||||||
const topics = require('../../topics');
|
const topics = require('../../topics');
|
||||||
@@ -17,9 +18,10 @@ const controller = module.exports;
|
|||||||
|
|
||||||
controller.list = async function (req, res) {
|
controller.list = async function (req, res) {
|
||||||
const { topicsPerPage } = await user.getSettings(req.uid);
|
const { topicsPerPage } = await user.getSettings(req.uid);
|
||||||
const page = parseInt(req.query.page, 10) || 1;
|
let { page, after } = req.query;
|
||||||
const start = Math.max(0, (page - 1) * topicsPerPage);
|
page = parseInt(page, 10) || 1;
|
||||||
const stop = start + topicsPerPage - 1;
|
let start = Math.max(0, (page - 1) * topicsPerPage);
|
||||||
|
let stop = start + topicsPerPage - 1;
|
||||||
|
|
||||||
const [userSettings, userPrivileges] = await Promise.all([
|
const [userSettings, userPrivileges] = await Promise.all([
|
||||||
user.getSettings(req.uid),
|
user.getSettings(req.uid),
|
||||||
@@ -31,6 +33,7 @@ controller.list = async function (req, res) {
|
|||||||
cid: '-1',
|
cid: '-1',
|
||||||
start: start,
|
start: start,
|
||||||
stop: stop,
|
stop: stop,
|
||||||
|
after,
|
||||||
sort: req.query.sort,
|
sort: req.query.sort,
|
||||||
settings: userSettings,
|
settings: userSettings,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
@@ -55,7 +58,18 @@ controller.list = async function (req, res) {
|
|||||||
({ tids, topicCount } = await topics.getSortedTopics(cidQuery));
|
({ tids, topicCount } = await topics.getSortedTopics(cidQuery));
|
||||||
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
|
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||||
} else {
|
} 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);
|
topicCount = await categories.getTopicCount(cidQuery);
|
||||||
}
|
}
|
||||||
data.topicCount = topicCount;
|
data.topicCount = topicCount;
|
||||||
|
|||||||
Reference in New Issue
Block a user