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