mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
fix: use categories.getTopicIds instead of duplicating existing logic to get world tids
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
|
|
||||||
const db = require('../../database');
|
|
||||||
const user = require('../../user');
|
const user = require('../../user');
|
||||||
const topics = require('../../topics');
|
const topics = require('../../topics');
|
||||||
|
|
||||||
@@ -30,14 +29,6 @@ controller.list = async function (req, res) {
|
|||||||
const start = Math.max(0, (page - 1) * topicsPerPage);
|
const start = Math.max(0, (page - 1) * topicsPerPage);
|
||||||
const stop = start + topicsPerPage - 1;
|
const stop = start + topicsPerPage - 1;
|
||||||
|
|
||||||
const sortToSet = {
|
|
||||||
recently_replied: `cid:-1:tids`,
|
|
||||||
recently_created: `cid:-1:tids:create`,
|
|
||||||
most_posts: `cid:-1:tids:posts`,
|
|
||||||
most_votes: `cid:-1:tids:votes`,
|
|
||||||
most_views: `cid:-1:tids:views`,
|
|
||||||
};
|
|
||||||
|
|
||||||
const [userPrivileges, tagData, userSettings, rssToken] = await Promise.all([
|
const [userPrivileges, tagData, userSettings, rssToken] = await Promise.all([
|
||||||
privileges.categories.get('-1', req.uid),
|
privileges.categories.get('-1', req.uid),
|
||||||
helpers.getSelectedTag(req.query.tag),
|
helpers.getSelectedTag(req.query.tag),
|
||||||
@@ -45,16 +36,8 @@ controller.list = async function (req, res) {
|
|||||||
user.auth.getFeedToken(req.uid),
|
user.auth.getFeedToken(req.uid),
|
||||||
]);
|
]);
|
||||||
const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;
|
const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;
|
||||||
|
|
||||||
let tids = await db.getSortedSetRevRange(sortToSet[sort], 0, 499);
|
|
||||||
const isMembers = await db.isSortedSetMembers(`uid:${req.uid}:inbox`, tids);
|
|
||||||
tids = tids.filter((tid, idx) => isMembers[idx]);
|
|
||||||
const count = tids.length;
|
|
||||||
tids = tids.slice(start, stop + 1);
|
|
||||||
|
|
||||||
const targetUid = await user.getUidByUserslug(req.query.author);
|
const targetUid = await user.getUidByUserslug(req.query.author);
|
||||||
|
const cidQuery = {
|
||||||
const data = await categories.getCategoryById({
|
|
||||||
uid: req.uid,
|
uid: req.uid,
|
||||||
cid: '-1',
|
cid: '-1',
|
||||||
start: start,
|
start: start,
|
||||||
@@ -64,12 +47,14 @@ controller.list = async function (req, res) {
|
|||||||
query: req.query,
|
query: req.query,
|
||||||
tag: req.query.tag,
|
tag: req.query.tag,
|
||||||
targetUid: targetUid,
|
targetUid: targetUid,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const data = await categories.getCategoryById(cidQuery);
|
||||||
data.name = '[[activitypub:world.name]]';
|
data.name = '[[activitypub:world.name]]';
|
||||||
delete data.children;
|
delete data.children;
|
||||||
|
|
||||||
data.topicCount = count;
|
const tids = await categories.getTopicIds(cidQuery);
|
||||||
|
data.topicCount = tids.length;
|
||||||
data.topics = await topics.getTopicsByTids(tids, { uid: req.uid });
|
data.topics = await topics.getTopicsByTids(tids, { uid: req.uid });
|
||||||
topics.calculateTopicIndices(data.topics, start);
|
topics.calculateTopicIndices(data.topics, start);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user