From 718e518e7f3cfebae9c090b6401c71d6e5ee57cc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 20 Mar 2026 12:12:56 -0400 Subject: [PATCH] feat: upgrade script for #14113 --- src/upgrades/4.11.0/backfill-user-cids.js | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/upgrades/4.11.0/backfill-user-cids.js diff --git a/src/upgrades/4.11.0/backfill-user-cids.js b/src/upgrades/4.11.0/backfill-user-cids.js new file mode 100644 index 0000000000..9c6d681b3a --- /dev/null +++ b/src/upgrades/4.11.0/backfill-user-cids.js @@ -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, + }); + }, +};