feat: show topic follower counts (#13326)

fix upgrade script dates
add upgrade script to count topic followers for each topic
This commit is contained in:
Barış Soner Uşaklı
2025-04-15 10:07:45 -04:00
committed by GitHub
parent 5d94f2cad4
commit bf2d4c46f8
7 changed files with 59 additions and 19 deletions

View File

@@ -7,7 +7,7 @@ const crypto = require('crypto');
module.exports = {
name: 'Normalize topic thumbnails, post & user uploads to same format',
timestamp: Date.UTC(2021, 1, 7),
timestamp: Date.UTC(2025, 3, 4),
method: async function () {
const { progress } = this;

View File

@@ -0,0 +1,35 @@
'use strict';
const db = require('../../database');
const batch = require('../../batch');
module.exports = {
name: 'Set "followercount" on each topic object',
timestamp: Date.UTC(2025, 3, 15),
method: async function () {
const { progress } = this;
progress.total = await db.sortedSetCard('topics:tid');
await batch.processSortedSet('topics:tid', async (tids) => {
const keys = tids.map(tid => `tid:${tid}:followers`);
const followerCounts = await db.setsCount(keys);
const bulkSet = [];
followerCounts.forEach((count, idx) => {
const tid = tids[idx];
if (count > 0) {
bulkSet.push([`topic:${tid}`, {followercount: count}]);
}
});
await db.setObjectBulk(bulkSet);
progress.incr(tids.length);
}, {
batch: 500,
});
},
};