From 06f66337fb7c3a8cef14b132260169548a78eb23 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 4 Nov 2014 19:05:55 -0500 Subject: [PATCH] anon checks less db calls for uid 0 --- src/favourites.js | 14 ++++++++++++++ src/posts.js | 18 ++++++++++++++++++ src/privileges/posts.js | 7 +------ src/user.js | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/favourites.js b/src/favourites.js index 123e014bc9..518b796f96 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -195,6 +195,9 @@ var async = require('async'), }; Favourites.hasVoted = function(pid, uid, callback) { + if (!parseInt(uid, 10)) { + return callback(null, {upvoted: false, downvoted: false}); + } db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function(err, hasVoted) { if (err) { return callback(err); @@ -205,6 +208,10 @@ var async = require('async'), }; Favourites.getVoteStatusByPostIDs = function(pids, uid, callback) { + if (!parseInt(uid, 10)) { + var data = pids.map(function() {return false;}); + return callback(null, {upvotes: data, downvotes: data}); + } var upvoteSets = [], downvoteSets = []; @@ -284,10 +291,17 @@ var async = require('async'), } Favourites.hasFavourited = function(pid, uid, callback) { + if (!parseInt(uid, 10)) { + return callback(null, false); + } db.isSetMember('pid:' + pid + ':users_favourited', uid, callback); }; Favourites.getFavouritesByPostIDs = function(pids, uid, callback) { + if (!parseInt(uid, 10)) { + return callback(null, pids.map(function() {return false;})); + } + var sets = []; for (var i=0; i