mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #7921, dont create wrong entries in db for flag
upgrade script to remove wrong entries
This commit is contained in:
@@ -445,7 +445,7 @@ Flags.getTargetCid = async function (type, id) {
|
||||
if (type === 'post') {
|
||||
return await posts.getCidByPid(id);
|
||||
}
|
||||
return id;
|
||||
return null;
|
||||
};
|
||||
|
||||
Flags.update = function (flagId, uid, changeset, callback) {
|
||||
|
||||
28
src/upgrades/1.13.0/clean_flag_byCid.js
Normal file
28
src/upgrades/1.13.0/clean_flag_byCid.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Clean flag byCid zsets',
|
||||
timestamp: Date.UTC(2019, 8, 24),
|
||||
method: async function (callback) {
|
||||
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));
|
||||
const bulkRemove = [];
|
||||
for (const flagObj of flagData) {
|
||||
if (flagObj && flagObj.type === 'user' && flagObj.targetId && flagObj.flagId) {
|
||||
bulkRemove.push(['flags:byCid:' + flagObj.targetId, flagObj.flagId]);
|
||||
}
|
||||
}
|
||||
|
||||
await db.sortedSetRemoveBulk(bulkRemove);
|
||||
}, {
|
||||
progress: progress,
|
||||
});
|
||||
callback();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user