fix: #8287, dont readd user after deletion
don't add user uid back to users:* sorted sets if they are deleted upgrade script to fix users:* sorted setsv1.18.x
parent
4d6b2ec3ce
commit
9d153fd388
@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix user sorted sets',
|
||||
timestamp: Date.UTC(2020, 4, 2),
|
||||
method: async function (callback) {
|
||||
const progress = this.progress;
|
||||
const nextUid = await db.getObjectField('global', 'nextUid');
|
||||
const allUids = [];
|
||||
for (let i = 1; i <= nextUid; i++) {
|
||||
allUids.push(i);
|
||||
}
|
||||
|
||||
progress.total = nextUid;
|
||||
let totalUserCount = 0;
|
||||
|
||||
await db.delete('user:null');
|
||||
await db.sortedSetsRemove([
|
||||
'users:joindate',
|
||||
'users:reputation',
|
||||
'users:postcount',
|
||||
], 'null');
|
||||
|
||||
await batch.processArray(allUids, async function (uids) {
|
||||
progress.incr(uids.length);
|
||||
const userData = await db.getObjects(uids.map(id => 'user:' + id));
|
||||
|
||||
await Promise.all(userData.map(async function (userData, index) {
|
||||
if (!userData || !userData.uid) {
|
||||
await db.sortedSetsRemove([
|
||||
'users:joindate',
|
||||
'users:reputation',
|
||||
'users:postcount',
|
||||
], uids[index]);
|
||||
if (userData && !userData.uid) {
|
||||
await db.delete('user:' + uids[index]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
totalUserCount += 1;
|
||||
await db.sortedSetAddBulk([
|
||||
['users:joindate', userData.joindate, uids[index]],
|
||||
['users:reputation', userData.reputation, uids[index]],
|
||||
['users:postcount', userData.postcount, uids[index]],
|
||||
]);
|
||||
}));
|
||||
}, {
|
||||
progress: progress,
|
||||
batch: 500,
|
||||
});
|
||||
|
||||
await db.setObjectField('global', 'userCount', totalUserCount);
|
||||
callback();
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue