mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 18:06:07 +02:00
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:
committed by
GitHub
parent
5d94f2cad4
commit
bf2d4c46f8
@@ -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;
|
||||
|
||||
|
||||
35
src/upgrades/4.3.0/topic_follower_counts.js
Normal file
35
src/upgrades/4.3.0/topic_follower_counts.js
Normal 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,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user