fix: username, email history disappering if content was deleted

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 074d7dfd86
commit 91d9333a50

@ -348,6 +348,7 @@ Flags.create = async function (type, id, uid, reason, timestamp) {
flagId: flagId,
type: type,
targetId: id,
targetUid: targetUid,
datetime: timestamp,
}),
Flags.addReport(flagId, type, id, uid, reason, timestamp),
@ -573,8 +574,7 @@ Flags.resolveFlag = async function (type, id, uid) {
Flags.getHistory = async function (flagId) {
const uids = [];
let history = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':history', 0, -1);
const flagData = await db.getObjectFields('flag:' + flagId, ['type', 'targetId']);
const targetUid = await Flags.getTargetUid(flagData.type, flagData.targetId);
const targetUid = await db.getObjectField('flag:' + flagId, 'targetUid');
history = history.map(function (entry) {
entry.value = JSON.parse(entry.value);

@ -0,0 +1,37 @@
'use strict';
const db = require('../../database');
const batch = require('../../batch');
const posts = require('../../posts');
module.exports = {
name: 'Add target uid to flag objects',
timestamp: Date.UTC(2020, 7, 22),
method: async function () {
const progress = this.progress;
await batch.processSortedSet('flags:datetime', async function (flagIds) {
progress.incr(flagIds.length);
const flagData = await db.getObjects(flagIds.map(id => 'flag:' + id));
for (const flagObj of flagData) {
/* eslint-disable no-await-in-loop */
if (flagObj) {
const targetId = flagObj.targetId;
if (targetId) {
if (flagObj.type === 'post') {
const targetUid = await posts.getPostField(targetId, 'uid');
if (targetUid) {
await db.setObjectField('flag:' + flagObj.flagId, 'targetUid', targetUid);
}
} else if (flagObj.type === 'user') {
await db.setObjectField('flag:' + flagObj.flagId, 'targetUid', targetId);
}
}
}
}
}, {
progress: progress,
batch: 500,
});
},
};
Loading…
Cancel
Save