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