From 5ebcdb18068e389d0da957b3aeec24b5f27d4ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 2 May 2020 15:34:58 -0400 Subject: [PATCH] fix: #8287, fix users:flags as well --- src/flags.js | 3 +-- src/upgrades/1.13.3/fix_users_sorted_sets.js | 5 +++++ src/user/posts.js | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/flags.js b/src/flags.js index c3c3f625c8..d65cb44955 100644 --- a/src/flags.js +++ b/src/flags.js @@ -296,8 +296,7 @@ Flags.create = async function (type, id, uid, reason, timestamp) { if (type === 'post') { await db.sortedSetAdd('flags:byPid:' + id, timestamp, flagId); // by target pid if (targetUid) { - await db.sortedSetIncrBy('users:flags', 1, targetUid); - await user.incrementUserFieldBy(targetUid, 'flags', 1); + await user.incrementUserFlagsBy(targetUid, 1); } } diff --git a/src/upgrades/1.13.3/fix_users_sorted_sets.js b/src/upgrades/1.13.3/fix_users_sorted_sets.js index 8e4c992905..3a6b947fa4 100644 --- a/src/upgrades/1.13.3/fix_users_sorted_sets.js +++ b/src/upgrades/1.13.3/fix_users_sorted_sets.js @@ -22,6 +22,7 @@ module.exports = { 'users:joindate', 'users:reputation', 'users:postcount', + 'users:flags', ], 'null'); await batch.processArray(allUids, async function (uids) { @@ -34,6 +35,7 @@ module.exports = { 'users:joindate', 'users:reputation', 'users:postcount', + 'users:flags', ], uids[index]); if (userData && !userData.uid) { await db.delete('user:' + uids[index]); @@ -46,6 +48,9 @@ module.exports = { ['users:reputation', userData.reputation, uids[index]], ['users:postcount', userData.postcount, uids[index]], ]); + if (userData.hasOwnProperty('flags') && parseInt(userData.flags, 10) > 0) { + await db.sortedSetAdd('users:flags', userData.flags, uids[index]); + } })); }, { progress: progress, diff --git a/src/user/posts.js b/src/user/posts.js index 95c96e51d4..e7e9174845 100644 --- a/src/user/posts.js +++ b/src/user/posts.js @@ -74,6 +74,10 @@ module.exports = function (User) { return await incrementUserFieldAndSetBy(uid, 'reputation', 'users:reputation', value); }; + User.incrementUserFlagsBy = async function (uid, value) { + return await incrementUserFieldAndSetBy(uid, 'flags', 'users:flags', value); + }; + async function incrementUserFieldAndSetBy(uid, field, set, value) { value = parseInt(value, 10); if (!value || !field || !(parseInt(uid, 10) > 0)) {