mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-05 21:17:05 +02:00
optimize queries
This commit is contained in:
14
src/posts.js
14
src/posts.js
@@ -404,15 +404,25 @@ var async = require('async'),
|
||||
|
||||
var tids = posts.map(function(post) {
|
||||
return post.tid;
|
||||
}).filter(function(tid, index, array) {
|
||||
return array.indexOf(tid) === index;
|
||||
});
|
||||
|
||||
topics.getTopicsFields(tids, ['cid'], function(err, topics) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var cids = topics.map(function(topic) {
|
||||
return topic.cid;
|
||||
var map = {};
|
||||
topics.forEach(function(topic) {
|
||||
if (topic) {
|
||||
map[topic.tid] = topic.cid;
|
||||
}
|
||||
});
|
||||
|
||||
var cids = posts.map(function(post) {
|
||||
return map[post.tid];
|
||||
})
|
||||
|
||||
callback(null, cids);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user