mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 09:55:47 +01:00
optimize queries
This commit is contained in:
@@ -439,15 +439,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Groups.getUserGroups = function(uids, callback) {
|
Groups.getUserGroups = function(uids, callback) {
|
||||||
var ignoredGroups = ['registered-users'];
|
|
||||||
|
|
||||||
db.getSetMembers('groups', function(err, groupNames) {
|
db.getSetMembers('groups', function(err, groupNames) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupKeys = groupNames.filter(function(groupName) {
|
var groupKeys = groupNames.filter(function(groupName) {
|
||||||
return ignoredGroups.indexOf(groupName) === -1;
|
return groupName !== 'registered-users' && groupName.indexOf(':privileges:') === -1;
|
||||||
}).map(function(groupName) {
|
}).map(function(groupName) {
|
||||||
return 'group:' + groupName;
|
return 'group:' + groupName;
|
||||||
});
|
});
|
||||||
|
|||||||
14
src/posts.js
14
src/posts.js
@@ -404,15 +404,25 @@ var async = require('async'),
|
|||||||
|
|
||||||
var tids = posts.map(function(post) {
|
var tids = posts.map(function(post) {
|
||||||
return post.tid;
|
return post.tid;
|
||||||
|
}).filter(function(tid, index, array) {
|
||||||
|
return array.indexOf(tid) === index;
|
||||||
});
|
});
|
||||||
|
|
||||||
topics.getTopicsFields(tids, ['cid'], function(err, topics) {
|
topics.getTopicsFields(tids, ['cid'], function(err, topics) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
var cids = topics.map(function(topic) {
|
var map = {};
|
||||||
return topic.cid;
|
topics.forEach(function(topic) {
|
||||||
|
if (topic) {
|
||||||
|
map[topic.tid] = topic.cid;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var cids = posts.map(function(post) {
|
||||||
|
return map[post.tid];
|
||||||
|
})
|
||||||
|
|
||||||
callback(null, cids);
|
callback(null, cids);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ var async = require('async'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var postKeys = pids.map(function(pid) {
|
var postKeys = pids.filter(Boolean).map(function(pid) {
|
||||||
return 'post:' + pid;
|
return 'post:' + pid;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -379,14 +379,19 @@ var async = require('async'),
|
|||||||
results.users.forEach(function(user) {
|
results.users.forEach(function(user) {
|
||||||
users[user.uid] = user;
|
users[user.uid] = user;
|
||||||
});
|
});
|
||||||
|
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.indices[index] + 1;
|
||||||
post.timestamp = utils.toISOString(post.timestamp);
|
post.timestamp = utils.toISOString(post.timestamp);
|
||||||
|
tidToPost[post.tid] = post;
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, postData);
|
var teasers = tids.map(function(tid) {
|
||||||
|
return tidToPost[tid];
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, teasers);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user