mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
late night optimizations
-isMemberOfSets returns true/false instead of 1/0 -when loading the posts of a topic only get the userdata for each user once, before this commit if a topic had 10 posts from 2 different users we were getting the user data for each user 5 times (drunk) -getVoteStatusByPostIDs and getFavouritesByPostIDs no longer make pids.length calls to the db, they use isMemberOfSets now -getUserInfoForPost renamed to getUserInfoForPosts and doesnt make uids.length calls to db, uses getMultipleUserFields instead
This commit is contained in:
@@ -101,7 +101,7 @@ var async = require('async'),
|
||||
if (meta.config['reputation:disabled'] === false) {
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
|
||||
toggleVote('upvote', pid, uid, callback);
|
||||
};
|
||||
|
||||
@@ -155,8 +155,21 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Favourites.getVoteStatusByPostIDs = function(pids, uid, callback) {
|
||||
async.map(pids, function(pid, next) {
|
||||
Favourites.hasVoted(pid, uid, next);
|
||||
var upvoteSets = [],
|
||||
downvoteSets = [];
|
||||
|
||||
for (var i=0; i<pids.length; ++i) {
|
||||
upvoteSets.push('pid:' + pids[i] + ':upvote');
|
||||
downvoteSets.push('pid:' + pids[i] + ':downvote');
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
db.isMemberOfSets(upvoteSets, uid, next);
|
||||
},
|
||||
downvotes: function(next) {
|
||||
db.isMemberOfSets(downvoteSets, uid, next);
|
||||
}
|
||||
}, callback);
|
||||
};
|
||||
|
||||
@@ -225,9 +238,12 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Favourites.getFavouritesByPostIDs = function(pids, uid, callback) {
|
||||
async.map(pids, function(pid, next) {
|
||||
Favourites.hasFavourited(pid, uid, next);
|
||||
}, callback);
|
||||
var sets = [];
|
||||
for (var i=0; i<pids.length; ++i) {
|
||||
sets.push('pid:' + pids[i] + ':users_favourited');
|
||||
}
|
||||
|
||||
db.isMemberOfSets(sets, uid, callback);
|
||||
};
|
||||
|
||||
Favourites.getFavouritedUidsByPids = function(pids, callback) {
|
||||
|
||||
Reference in New Issue
Block a user