feat: upgrade script for #14113

This commit is contained in:
Julian Lam
2026-03-20 12:12:56 -04:00
parent bb1e66020a
commit 718e518e7f

View 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,
});
},
};