mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
shorter getTeasers
This commit is contained in:
@@ -16,7 +16,7 @@ var async = require('async'),
|
|||||||
module.exports = function(Posts) {
|
module.exports = function(Posts) {
|
||||||
|
|
||||||
Posts.getPostSummaryByPids = function(pids, uid, options, callback) {
|
Posts.getPostSummaryByPids = function(pids, uid, options, callback) {
|
||||||
if (!pids || !Array.isArray(pids) || !pids.length) {
|
if (!Array.isArray(pids) || !pids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,8 @@ module.exports = function(Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
counts: function(next) {
|
topics: function(next) {
|
||||||
Topics.getTopicsFields(tids, ['postcount'], function(err, topics) {
|
Topics.getTopicsFields(tids, ['postcount'], next);
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
topics = topics.map(function(topic) {
|
|
||||||
return topic && (parseInt(topic.postcount, 10) || 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
next(null, topics);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
pids: function(next) {
|
pids: function(next) {
|
||||||
async.map(tids, function(tid, next) {
|
async.map(tids, function(tid, next) {
|
||||||
@@ -42,6 +33,10 @@ module.exports = function(Topics) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var counts = results.topics.map(function(topic) {
|
||||||
|
return topic && (parseInt(topic.postcount, 10) || 0);
|
||||||
|
});
|
||||||
|
|
||||||
results.pids = results.pids.filter(Boolean);
|
results.pids = results.pids.filter(Boolean);
|
||||||
|
|
||||||
posts.getPostsFields(results.pids, ['pid', 'uid', 'timestamp', 'tid'], function(err, postData) {
|
posts.getPostsFields(results.pids, ['pid', 'uid', 'timestamp', 'tid'], function(err, postData) {
|
||||||
@@ -74,7 +69,7 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
var teasers = tids.map(function(tid, index) {
|
var teasers = tids.map(function(tid, index) {
|
||||||
if (tidToPost[tid]) {
|
if (tidToPost[tid]) {
|
||||||
tidToPost[tid].index = results.counts[index];
|
tidToPost[tid].index = counts[index];
|
||||||
}
|
}
|
||||||
return tidToPost[tid];
|
return tidToPost[tid];
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user