fix: #8287, fix users:flags as well

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 919034a7db
commit 5ebcdb1806

@ -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);
}
}

@ -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,

@ -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)) {

Loading…
Cancel
Save