Node.js based forum software built for the modern web
remove unnecessary checks
Barış Soner Uşaklıf1b84921642b
diff --git a/src/categories.js b/src/categories.jsindex 706e29448c..8d15745d9c 100644--- a/src/categories.js+++ b/src/categories.js@@ -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]]'));diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.jsindex 5936863102..9c36829fd1 100644--- a/src/categories/recentreplies.js+++ b/src/categories/recentreplies.js@@ -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) {diff --git a/src/categories/topics.js b/src/categories/topics.jsindex a346307e9c..50278f529b 100644--- a/src/categories/topics.js+++ b/src/categories/topics.js@@ -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 });}diff --git a/src/groups/posts.js b/src/groups/posts.jsindex bd829f3d58..425a9228e9 100644--- a/src/groups/posts.js+++ b/src/groups/posts.js@@ -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) {diff --git a/src/messaging.js b/src/messaging.jsindex 0ad092cf5e..99467959b3 100644--- a/src/messaging.js+++ b/src/messaging.js@@ -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, []);}diff --git a/src/notifications.js b/src/notifications.jsindex d5505f88dd..fb55cd8ab3 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -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();}diff --git a/src/plugins/data.js b/src/plugins/data.jsindex afb8d095ab..3027b491c4 100644--- a/src/plugins/data.js+++ b/src/plugins/data.js@@ -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) {diff --git a/src/search.js b/src/search.jsindex da6ab603bf..3ed7f4ef35 100644--- a/src/search.js+++ b/src/search.js@@ -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);diff --git a/src/topics/posts.js b/src/topics/posts.jsindex 3ed8deafc7..08b5db8e01 100644--- a/src/topics/posts.js+++ b/src/topics/posts.js@@ -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();}diff --git a/src/topics/unread.js b/src/topics/unread.jsindex 2cee549ba9..073a680358 100644--- a/src/topics/unread.js+++ b/src/topics/unread.js@@ -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);}diff --git a/src/user/notifications.js b/src/user/notifications.jsindex 1eedf6a58c..e8873c88f2 100644--- a/src/user/notifications.js+++ b/src/user/notifications.js@@ -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, []);}diff --git a/test/database/sorted.js b/test/database/sorted.jsindex 1cf46204df..67bb9831f1 100644--- a/test/database/sorted.js+++ b/test/database/sorted.js@@ -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 () {