mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-27 06:40:37 +01:00
feat: upgrade script for #14113
This commit is contained in:
30
src/upgrades/4.11.0/backfill-user-cids.js
Normal file
30
src/upgrades/4.11.0/backfill-user-cids.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Backfill user posted categories',
|
||||
timestamp: Date.UTC(2026, 2, 20),
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
await batch.processSortedSet('posts:pid', async (pids) => {
|
||||
const postData = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['uid', 'cid']);
|
||||
const bulkIncr = [];
|
||||
postData.forEach((post) => {
|
||||
if (post && post.uid && post.cid) {
|
||||
bulkIncr.push([`uid:${post.uid}:cids`, 1, post.cid]);
|
||||
}
|
||||
});
|
||||
|
||||
if (bulkIncr.length) {
|
||||
await db.sortedSetIncrByBulk(bulkIncr);
|
||||
}
|
||||
|
||||
progress.incr(pids.length);
|
||||
}, {
|
||||
batch: 500,
|
||||
progress,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user