From 2bcf7f72d21ca528b8b43c157751056880f0e069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 18 Jun 2020 23:24:03 -0400 Subject: [PATCH] fix: follower count going out of sync with real follower count --- src/user/follow.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/user/follow.js b/src/user/follow.js index 9e37a62a8d..c8c281f927 100644 --- a/src/user/follow.js +++ b/src/user/follow.js @@ -36,8 +36,6 @@ module.exports = function (User) { ['following:' + uid, now, theiruid], ['followers:' + theiruid, now, uid], ]), - User.incrementUserFieldBy(uid, 'followingCount', 1), - User.incrementUserFieldBy(theiruid, 'followerCount', 1), ]); } else { if (!isFollowing) { @@ -48,10 +46,17 @@ module.exports = function (User) { ['following:' + uid, theiruid], ['followers:' + theiruid, uid], ]), - User.decrementUserFieldBy(uid, 'followingCount', 1), - User.decrementUserFieldBy(theiruid, 'followerCount', 1), ]); } + + const [followingCount, followerCount] = await Promise.all([ + db.sortedSetCard('following:' + uid), + db.sortedSetCard('followers:' + theiruid), + ]); + await Promise.all([ + User.setUserField(uid, 'followingCount', followingCount), + User.setUserField(theiruid, 'followerCount', followerCount), + ]); } User.getFollowing = async function (uid, start, stop) {