mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	fix: #7102
This commit is contained in:
		| @@ -29,6 +29,9 @@ module.exports = function (redisClient, module) { | |||||||
|  |  | ||||||
| 	function sortedSetRange(method, key, start, stop, withScores, callback) { | 	function sortedSetRange(method, key, start, stop, withScores, callback) { | ||||||
| 		if (Array.isArray(key)) { | 		if (Array.isArray(key)) { | ||||||
|  | 			if (!key.length) { | ||||||
|  | 				return setImmediate(callback, null, []); | ||||||
|  | 			} | ||||||
| 			const batch = redisClient.batch(); | 			const batch = redisClient.batch(); | ||||||
| 			key.forEach((key) => { | 			key.forEach((key) => { | ||||||
| 				batch[method]([key, start, stop, 'WITHSCORES']); | 				batch[method]([key, start, stop, 'WITHSCORES']); | ||||||
|   | |||||||
| @@ -47,12 +47,11 @@ module.exports = function (Topics) { | |||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function (next) { | 			function (next) { | ||||||
| 				if (params.term === 'alltime') { | 				if (params.term === 'alltime') { | ||||||
| 					var key = 'topics:' + params.sort; |  | ||||||
| 					if (params.cids) { | 					if (params.cids) { | ||||||
| 						key = getCidSets(params.cids, params.sort); | 						getCidTids(params.cids, params.sort, next); | ||||||
|  | 					} else { | ||||||
|  | 						db.getSortedSetRevRange('topics:' + params.sort, 0, 199, next); | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| 					db.getSortedSetRevRange(key, 0, 199, next); |  | ||||||
| 				} else { | 				} else { | ||||||
| 					Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term, next); | 					Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term, next); | ||||||
| 				} | 				} | ||||||
| @@ -70,17 +69,28 @@ module.exports = function (Topics) { | |||||||
| 		], callback); | 		], callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	function getCidSets(cids, sort) { | 	function getCidTids(cids, sort, callback) { | ||||||
| 		const keys = []; | 		const sets = []; | ||||||
|  | 		const pinnedSets = []; | ||||||
| 		cids.forEach(function (cid) { | 		cids.forEach(function (cid) { | ||||||
| 			if (sort === 'recent') { | 			if (sort === 'recent') { | ||||||
| 				keys.push('cid:' + cid + ':tids:lastposttime'); | 				sets.push('cid:' + cid + ':tids:lastposttime'); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			keys.push('cid:' + cid + ':tids' + (sort ? ':' + sort : '')); | 			sets.push('cid:' + cid + ':tids' + (sort ? ':' + sort : '')); | ||||||
| 			keys.push('cid:' + cid + ':tids:pinned'); | 			pinnedSets.push('cid:' + cid + ':tids:pinned'); | ||||||
| 		}); | 		}); | ||||||
| 		return keys; | 		async.waterfall([ | ||||||
|  | 			function (next) { | ||||||
|  | 				async.parallel({ | ||||||
|  | 					tids: async.apply(db.getSortedSetRevRange, sets, 0, 199), | ||||||
|  | 					pinnedTids: async.apply(db.getSortedSetRevRange, pinnedSets, 0, -1), | ||||||
|  | 				}, next); | ||||||
|  | 			}, | ||||||
|  | 			function (results, next) { | ||||||
|  | 				next(null, results.pinnedTids.concat(results.tids)); | ||||||
|  | 			}, | ||||||
|  | 		], callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	function sortTids(tids, params, callback) { | 	function sortTids(tids, params, callback) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user