Skip to content

Node.js based forum software built for the modern web

fix: #8287, fix users:flags as well

Barış Soner Uşaklı5ebcdb18068e
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)) {