mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: return correct number of suggested topics
This commit is contained in:
@@ -17,26 +17,25 @@ module.exports = function (Topics) {
|
|||||||
getSearchTids(tid, uid),
|
getSearchTids(tid, uid),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tids = tagTids.concat(searchTids);
|
tids = tagTids.concat(searchTids).filter(_tid => _tid !== tid);
|
||||||
tids = tids.filter(_tid => _tid !== tid);
|
|
||||||
tids = _.shuffle(_.uniq(tids));
|
|
||||||
let categoryTids = [];
|
let categoryTids = [];
|
||||||
if (stop !== -1 && tids.length < stop - start + 1) {
|
if (stop !== -1 && tids.length < stop - start + 1) {
|
||||||
categoryTids = await getCategoryTids(tid);
|
categoryTids = await getCategoryTids(tid);
|
||||||
}
|
}
|
||||||
tids = _.uniq(tids.concat(categoryTids)).slice(start, stop !== -1 ? stop + 1 : undefined);
|
tids = _.shuffle(_.uniq(tids.concat(categoryTids)));
|
||||||
tids = await privileges.topics.filterTids('topics:read', tids, uid);
|
tids = await privileges.topics.filterTids('topics:read', tids, uid);
|
||||||
|
|
||||||
let topicData = await Topics.getTopicsByTids(tids, uid);
|
let topicData = await Topics.getTopicsByTids(tids, uid);
|
||||||
topicData = topicData.filter(topic => topic && !topic.deleted && topic.tid !== tid);
|
topicData = topicData.filter(topic => topic && !topic.deleted && topic.tid !== tid);
|
||||||
topicData = await user.blocks.filter(uid, topicData);
|
topicData = await user.blocks.filter(uid, topicData);
|
||||||
|
topicData = topicData.slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||||
return topicData;
|
return topicData;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getTidsWithSameTags(tid) {
|
async function getTidsWithSameTags(tid) {
|
||||||
const tags = await Topics.getTopicTags(tid);
|
const tags = await Topics.getTopicTags(tid);
|
||||||
const tids = await db.getSortedSetRevRange(tags.map(tag => 'tag:' + tag + ':topics'), 0, -1);
|
const tids = await db.getSortedSetRevRange(tags.map(tag => 'tag:' + tag + ':topics'), 0, -1);
|
||||||
return _.uniq(tids).map(Number);
|
return _.shuffle(_.uniq(tids)).slice(0, 10).map(Number);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSearchTids(tid, uid) {
|
async function getSearchTids(tid, uid) {
|
||||||
@@ -49,7 +48,7 @@ module.exports = function (Topics) {
|
|||||||
uid: uid,
|
uid: uid,
|
||||||
returnIds: true,
|
returnIds: true,
|
||||||
});
|
});
|
||||||
return _.shuffle(data.tids).slice(0, 20).map(Number);
|
return _.shuffle(data.tids).slice(0, 10).map(Number);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCategoryTids(tid) {
|
async function getCategoryTids(tid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user