mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
faster getTeasers
got rid of getPostIndices
This commit is contained in:
@@ -203,7 +203,7 @@ module.exports = function(db, module) {
|
|||||||
|
|
||||||
module.sortedSetCard = function(key, callback) {
|
module.sortedSetCard = function(key, callback) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return callback();
|
return callback(null, 0);
|
||||||
}
|
}
|
||||||
db.collection('objects').count({_key: key}, function(err, count) {
|
db.collection('objects').count({_key: key}, function(err, count) {
|
||||||
count = parseInt(count, 10);
|
count = parseInt(count, 10);
|
||||||
|
|||||||
@@ -193,6 +193,9 @@ var async = require('async'),
|
|||||||
var cids = mapFilter(topics, 'cid');
|
var cids = mapFilter(topics, 'cid');
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
|
teasers: function(next) {
|
||||||
|
Topics.getTeasers(tids, uid, next);
|
||||||
|
},
|
||||||
users: function(next) {
|
users: function(next) {
|
||||||
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
||||||
},
|
},
|
||||||
@@ -205,9 +208,6 @@ var async = require('async'),
|
|||||||
isAdminOrMod: function(next) {
|
isAdminOrMod: function(next) {
|
||||||
privileges.categories.isAdminOrMod(cids, uid, next);
|
privileges.categories.isAdminOrMod(cids, uid, next);
|
||||||
},
|
},
|
||||||
teasers: function(next) {
|
|
||||||
Topics.getTeasers(tids, uid, next);
|
|
||||||
},
|
|
||||||
tags: function(next) {
|
tags: function(next) {
|
||||||
Topics.getTopicsTagsObjects(tids, next);
|
Topics.getTopicsTagsObjects(tids, next);
|
||||||
}
|
}
|
||||||
@@ -346,20 +346,29 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTeasers = function(tids, uid, callback) {
|
Topics.getTeasers = function(tids, uid, callback) {
|
||||||
if(!Array.isArray(tids)) {
|
if(!Array.isArray(tids) || !tids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.parallel({
|
||||||
|
counts: function(next) {
|
||||||
|
async.map(tids, function(tid, next) {
|
||||||
|
db.sortedSetCard('tid:' + tid + ':posts', next);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
pids: function(next) {
|
||||||
async.map(tids, function(tid, next) {
|
async.map(tids, function(tid, next) {
|
||||||
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, 0, function(err, data) {
|
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, 0, function(err, data) {
|
||||||
next(err, Array.isArray(data) && data.length ? data[0] : null);
|
next(err, Array.isArray(data) && data.length ? data[0] : null);
|
||||||
});
|
});
|
||||||
}, function(err, pids) {
|
}, next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var postKeys = pids.filter(Boolean).map(function(pid) {
|
var postKeys = results.pids.filter(Boolean).map(function(pid) {
|
||||||
return 'post:' + pid;
|
return 'post:' + pid;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -374,26 +383,20 @@ var async = require('async'),
|
|||||||
return array.indexOf(uid) === index;
|
return array.indexOf(uid) === index;
|
||||||
});
|
});
|
||||||
|
|
||||||
async.parallel({
|
|
||||||
users: function(next) {
|
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], function(err, usersData) {
|
||||||
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
|
||||||
},
|
|
||||||
indices: function(next) {
|
|
||||||
posts.getPostIndices(postData, uid, next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var users = {};
|
var users = {};
|
||||||
results.users.forEach(function(user) {
|
usersData.forEach(function(user) {
|
||||||
users[user.uid] = user;
|
users[user.uid] = user;
|
||||||
});
|
});
|
||||||
var tidToPost = {};
|
var tidToPost = {};
|
||||||
postData.forEach(function(post, index) {
|
postData.forEach(function(post, index) {
|
||||||
post.user = users[post.uid];
|
post.user = users[post.uid];
|
||||||
post.index = results.indices[index] + 1;
|
post.index = results.counts[index] + 1;
|
||||||
post.timestamp = utils.toISOString(post.timestamp);
|
post.timestamp = utils.toISOString(post.timestamp);
|
||||||
tidToPost[post.tid] = post;
|
tidToPost[post.tid] = post;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user