mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
use topic.getMainPids
This commit is contained in:
@@ -85,16 +85,14 @@ function searchInContent(query, data, callback) {
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
getMainPids(results.tids, next);
|
||||
topics.getMainPids(results.tids, next);
|
||||
},
|
||||
function(mainPids, next) {
|
||||
results.pids.forEach(function(pid) {
|
||||
if (mainPids.indexOf(pid.toString()) === -1) {
|
||||
mainPids.push(pid);
|
||||
}
|
||||
results.pids = mainPids.concat(results.pids).filter(function(pid, index, array) {
|
||||
return pid && array.indexOf(pid) === index;
|
||||
});
|
||||
|
||||
privileges.posts.filter('read', mainPids, data.uid, next);
|
||||
privileges.posts.filter('read', results.pids, data.uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
filterAndSort(pids, data, results.searchCategories, next);
|
||||
@@ -460,22 +458,6 @@ function searchInTags(query, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMainPids(tids, callback) {
|
||||
if (!Array.isArray(tids) || !tids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
topics.getTopicsFields(tids, ['mainPid'], function(err, topics) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
topics = topics.map(function(topic) {
|
||||
return topic && topic.mainPid && topic.mainPid.toString();
|
||||
}).filter(Boolean);
|
||||
callback(null, topics);
|
||||
});
|
||||
}
|
||||
|
||||
search.searchQuery = function(index, query, callback) {
|
||||
plugins.fireHook('filter:search.query', {
|
||||
index: index,
|
||||
|
||||
@@ -287,13 +287,17 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Topics.getMainPids = function(tids, callback) {
|
||||
if (!Array.isArray(tids) || !tids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var mainPids = topicData.map(function(topic) {
|
||||
return topic ? topic.mainPid : null;
|
||||
return topic && topic.mainPid;
|
||||
});
|
||||
callback(null, mainPids);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user