mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	handle empty set, add test
This commit is contained in:
		| @@ -36,6 +36,9 @@ module.exports = function (db, module) { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (Array.isArray(key)) { | 		if (Array.isArray(key)) { | ||||||
|  | 			if (!key.length) { | ||||||
|  | 				return setImmediate(callback, null, []); | ||||||
|  | 			} | ||||||
| 			key = { $in: key }; | 			key = { $in: key }; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ | |||||||
| var async = require('async'); | var async = require('async'); | ||||||
| var _ = require('lodash'); | var _ = require('lodash'); | ||||||
|  |  | ||||||
|  | const db = require('../database'); | ||||||
| var privileges = require('../privileges'); | var privileges = require('../privileges'); | ||||||
| var search = require('../search'); | var search = require('../search'); | ||||||
|  |  | ||||||
| @@ -46,15 +47,10 @@ module.exports = function (Topics) { | |||||||
| 				Topics.getTopicTags(tid, next); | 				Topics.getTopicTags(tid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (tags, next) { | 			function (tags, next) { | ||||||
| 				async.map(tags, function (tag, next) { | 				db.getSortedSetRevRange(tags.map(tag => 'tag:' + tag + ':topics'), 0, -1, next); | ||||||
| 					Topics.getTagTids(tag, 0, -1, next); |  | ||||||
| 				}, next); |  | ||||||
| 			}, |  | ||||||
| 			function (data, next) { |  | ||||||
| 				next(null, _.uniq(_.flatten(data))); |  | ||||||
| 			}, | 			}, | ||||||
| 			function (tids, next) { | 			function (tids, next) { | ||||||
| 				tids = tids.map(Number); | 				tids = _.uniq(tids).map(Number); | ||||||
| 				privileges.topics.filterTids('read', tids, uid, next); | 				privileges.topics.filterTids('read', tids, uid, next); | ||||||
| 			}, | 			}, | ||||||
| 		], callback); | 		], callback); | ||||||
|   | |||||||
| @@ -139,6 +139,14 @@ describe('Sorted Set methods', function () { | |||||||
| 				done(); | 				done(); | ||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should return empty array if keys is empty array', function (done) { | ||||||
|  | 			db.getSortedSetRange([], 0, -1, function (err, data) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				assert.deepStrictEqual(data, []); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	describe('getSortedSetRevRange()', function () { | 	describe('getSortedSetRevRange()', function () { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user