mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	remove unnecessary checks
This commit is contained in:
		| @@ -94,10 +94,6 @@ Categories.getAllCategories = function (uid, callback) { | |||||||
| 			db.getSortedSetRange('categories:cid', 0, -1, next); | 			db.getSortedSetRange('categories:cid', 0, -1, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (cids, next) { | 		function (cids, next) { | ||||||
| 			if (!Array.isArray(cids) || !cids.length) { |  | ||||||
| 				return next(null, []); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			Categories.getCategories(cids, uid, next); | 			Categories.getCategories(cids, uid, next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| @@ -123,16 +119,11 @@ Categories.getModerators = function (cid, callback) { | |||||||
| 			Groups.getMembers('cid:' + cid + ':privileges:moderate', 0, -1, next); | 			Groups.getMembers('cid:' + cid + ':privileges:moderate', 0, -1, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (uids, next) { | 		function (uids, next) { | ||||||
| 			if (!Array.isArray(uids) || !uids.length) { |  | ||||||
| 				return next(null, []); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next); | 			user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| Categories.getCategories = function (cids, uid, callback) { | Categories.getCategories = function (cids, uid, callback) { | ||||||
| 	if (!Array.isArray(cids)) { | 	if (!Array.isArray(cids)) { | ||||||
| 		return callback(new Error('[[error:invalid-cid]]')); | 		return callback(new Error('[[error:invalid-cid]]')); | ||||||
|   | |||||||
| @@ -186,10 +186,6 @@ module.exports = function (Categories) { | |||||||
| 				topics.getPids(tid, next); | 				topics.getPids(tid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (pids, next) { | 			function (pids, next) { | ||||||
| 				if (!Array.isArray(pids) || !pids.length) { |  | ||||||
| 					return callback(); |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				batch.processArray(pids, function (pids, next) { | 				batch.processArray(pids, function (pids, next) { | ||||||
| 					async.waterfall([ | 					async.waterfall([ | ||||||
| 						function (next) { | 						function (next) { | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ module.exports = function (Categories) { | |||||||
| 				topics.getTopicsByTids(tids, data.uid, next); | 				topics.getTopicsByTids(tids, data.uid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (topics, next) { | 			function (topics, next) { | ||||||
| 				if (!Array.isArray(topics) || !topics.length) { | 				if (!topics.length) { | ||||||
| 					return next(null, { topics: [], uid: data.uid }); | 					return next(null, { topics: [], uid: data.uid }); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,10 +58,6 @@ module.exports = function (Groups) { | |||||||
| 				db.getSortedSetRevRange('group:' + groupName + ':member:pids', 0, max - 1, next); | 				db.getSortedSetRevRange('group:' + groupName + ':member:pids', 0, max - 1, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (pids, next) { | 			function (pids, next) { | ||||||
| 				if (!Array.isArray(pids) || !pids.length) { |  | ||||||
| 					return callback(null, []); |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				privileges.posts.filter('read', pids, uid, next); | 				privileges.posts.filter('read', pids, uid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (pids, next) { | 			function (pids, next) { | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ Messaging.getMessages = function (params, callback) { | |||||||
| 			db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', start, stop, next); | 			db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', start, stop, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (mids, next) { | 		function (mids, next) { | ||||||
| 			if (!Array.isArray(mids) || !mids.length) { | 			if (!mids.length) { | ||||||
| 				return callback(null, []); | 				return callback(null, []); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -235,10 +235,6 @@ Notifications.pushGroup = function (notification, groupName, callback) { | |||||||
| 			groups.getMembers(groupName, 0, -1, next); | 			groups.getMembers(groupName, 0, -1, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (members, next) { | 		function (members, next) { | ||||||
| 			if (!Array.isArray(members) || !members.length) { |  | ||||||
| 				return callback(); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			Notifications.push(notification, members, next); | 			Notifications.push(notification, members, next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| @@ -387,7 +383,7 @@ Notifications.prune = function (callback) { | |||||||
| 			db.getSortedSetRangeByScore('notifications', 0, 500, '-inf', cutoffTime, next); | 			db.getSortedSetRangeByScore('notifications', 0, 500, '-inf', cutoffTime, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (nids, next) { | 		function (nids, next) { | ||||||
| 			if (!Array.isArray(nids) || !nids.length) { | 			if (!nids.length) { | ||||||
| 				return callback(); | 				return callback(); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,10 +18,6 @@ function getPluginPaths(callback) { | |||||||
| 			db.getSortedSetRange('plugins:active', 0, -1, next); | 			db.getSortedSetRange('plugins:active', 0, -1, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (plugins, next) { | 		function (plugins, next) { | ||||||
| 			if (!Array.isArray(plugins)) { |  | ||||||
| 				return next(); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			plugins = plugins.filter(function (plugin) { | 			plugins = plugins.filter(function (plugin) { | ||||||
| 				return plugin && typeof plugin === 'string'; | 				return plugin && typeof plugin === 'string'; | ||||||
| 			}).map(function (plugin) { | 			}).map(function (plugin) { | ||||||
|   | |||||||
| @@ -111,7 +111,7 @@ function filterAndSort(pids, data, callback) { | |||||||
| 			getMatchedPosts(pids, data, next); | 			getMatchedPosts(pids, data, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (posts, next) { | 		function (posts, next) { | ||||||
| 			if (!Array.isArray(posts) || !posts.length) { | 			if (!posts.length) { | ||||||
| 				return callback(null, pids); | 				return callback(null, pids); | ||||||
| 			} | 			} | ||||||
| 			posts = posts.filter(Boolean); | 			posts = posts.filter(Boolean); | ||||||
|   | |||||||
| @@ -239,7 +239,7 @@ module.exports = function (Topics) { | |||||||
| 					}, | 					}, | ||||||
| 					function (_pids, _next) { | 					function (_pids, _next) { | ||||||
| 						pids = _pids; | 						pids = _pids; | ||||||
| 						if (!Array.isArray(pids) || !pids.length) { | 						if (!pids.length) { | ||||||
| 							done = true; | 							done = true; | ||||||
| 							return next(); | 							return next(); | ||||||
| 						} | 						} | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ module.exports = function (Topics) { | |||||||
| 				Topics.getTopicsByTids(tids, params.uid, next); | 				Topics.getTopicsByTids(tids, params.uid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function (topicData, next) { | 			function (topicData, next) { | ||||||
| 				if (!Array.isArray(topicData) || !topicData.length) { | 				if (!topicData.length) { | ||||||
| 					return next(null, unreadTopics); | 					return next(null, unreadTopics); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -125,16 +125,16 @@ function getNotificationsFromSet(set, read, uid, start, stop, callback) { | |||||||
| 			db.getSortedSetRevRange(set, start, stop, next); | 			db.getSortedSetRevRange(set, start, stop, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (nids, next) { | 		function (nids, next) { | ||||||
| 			if (!Array.isArray(nids) || !nids.length) { |  | ||||||
| 				return callback(null, []); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			UserNotifications.getNotifications(nids, uid, next); | 			UserNotifications.getNotifications(nids, uid, next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| } | } | ||||||
|  |  | ||||||
| UserNotifications.getNotifications = function (nids, uid, callback) { | UserNotifications.getNotifications = function (nids, uid, callback) { | ||||||
|  | 	if (!Array.isArray(nids) || !nids.length) { | ||||||
|  | 		return callback(null, []); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	var notificationData = []; | 	var notificationData = []; | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function (next) { | 		function (next) { | ||||||
| @@ -177,10 +177,6 @@ UserNotifications.getDailyUnread = function (uid, callback) { | |||||||
| 			db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', yesterday, next); | 			db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', yesterday, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (nids, next) { | 		function (nids, next) { | ||||||
| 			if (!Array.isArray(nids) || !nids.length) { |  | ||||||
| 				return callback(null, []); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			UserNotifications.getNotifications(nids, uid, next); | 			UserNotifications.getNotifications(nids, uid, next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| @@ -231,7 +227,7 @@ UserNotifications.getUnreadByField = function (uid, field, values, callback) { | |||||||
| 		}, | 		}, | ||||||
| 		function (_nids, next) { | 		function (_nids, next) { | ||||||
| 			nids = _nids; | 			nids = _nids; | ||||||
| 			if (!Array.isArray(nids) || !nids.length) { | 			if (!nids.length) { | ||||||
| 				return callback(null, []); | 				return callback(null, []); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -69,6 +69,15 @@ describe('Sorted Set methods', function () { | |||||||
| 				done(); | 				done(); | ||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should return empty array if set does not exist', function (done) { | ||||||
|  | 			db.getSortedSetRange('doesnotexist', 0, -1, function (err, values) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				assert(Array.isArray(values)); | ||||||
|  | 				assert.equal(values.length, 0); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	describe('getSortedSetRevRange()', function () { | 	describe('getSortedSetRevRange()', function () { | ||||||
| @@ -122,6 +131,15 @@ describe('Sorted Set methods', function () { | |||||||
| 				done(); | 				done(); | ||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should return empty array if set does not exist', function (done) { | ||||||
|  | 			db.getSortedSetRangeByScore('doesnotexist', 0, -1, '-inf', 0, function (err, values) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				assert(Array.isArray(values)); | ||||||
|  | 				assert.equal(values.length, 0); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	describe('getSortedSetRevRangeByScore()', function () { | 	describe('getSortedSetRevRangeByScore()', function () { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user