From b8c08a541764660c5c1001e072da58bfcfe0d0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 22 Nov 2018 22:21:03 -0500 Subject: [PATCH] dont call db for guests --- src/topics/follow.js | 18 +++++++++--------- src/topics/unread.js | 11 +++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/topics/follow.js b/src/topics/follow.js index bb82d14aee..b34b36ca7f 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -173,37 +173,37 @@ module.exports = function (Topics) { db.isSetMembers('tid:' + tid + ':ignorers', uids, next); }, function (isIgnoring, next) { - var readingUids = uids.filter(function (uid, index) { - return uid && !isIgnoring[index]; - }); + const readingUids = uids.filter((uid, index) => uid && !isIgnoring[index]); next(null, readingUids); }, ], callback); }; Topics.filterWatchedTids = function (tids, uid, callback) { + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, []); + } async.waterfall([ function (next) { db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next); }, function (scores, next) { - tids = tids.filter(function (tid, index) { - return tid && !!scores[index]; - }); + tids = tids.filter((tid, index) => tid && !!scores[index]); next(null, tids); }, ], callback); }; Topics.filterNotIgnoredTids = function (tids, uid, callback) { + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, tids); + } async.waterfall([ function (next) { db.sortedSetScores('uid:' + uid + ':ignored_tids', tids, next); }, function (scores, next) { - tids = tids.filter(function (tid, index) { - return tid && !scores[index]; - }); + tids = tids.filter((tid, index) => tid && !scores[index]); next(null, tids); }, ], callback); diff --git a/src/topics/unread.js b/src/topics/unread.js index 4fafc28351..8e1466145b 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -516,14 +516,15 @@ module.exports = function (Topics) { }; Topics.filterNewTids = function (tids, uid, callback) { + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, []); + } async.waterfall([ function (next) { db.sortedSetScores('uid:' + uid + ':tids_read', tids, next); }, function (scores, next) { - tids = tids.filter(function (tid, index) { - return tid && !scores[index]; - }); + tids = tids.filter((tid, index) => tid && !scores[index]); next(null, tids); }, ], callback); @@ -535,9 +536,7 @@ module.exports = function (Topics) { db.sortedSetScores('topics:posts', tids, next); }, function (scores, next) { - tids = tids.filter(function (tid, index) { - return tid && scores[index] <= 1; - }); + tids = tids.filter((tid, index) => tid && scores[index] <= 1); next(null, tids); }, ], callback);