mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01: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
@@ -107,10 +107,10 @@
|
||||
"nodebb-plugin-spam-be-gone": "2.3.1",
|
||||
"nodebb-plugin-web-push": "0.7.3",
|
||||
"nodebb-rewards-essentials": "1.0.1",
|
||||
"nodebb-theme-harmony": "2.1.6",
|
||||
"nodebb-theme-harmony": "2.1.7",
|
||||
"nodebb-theme-lavender": "7.1.18",
|
||||
"nodebb-theme-peace": "2.2.39",
|
||||
"nodebb-theme-persona": "14.1.5",
|
||||
"nodebb-theme-peace": "2.2.40",
|
||||
"nodebb-theme-persona": "14.1.6",
|
||||
"nodebb-widget-essentials": "7.0.36",
|
||||
"nodemailer": "6.10.0",
|
||||
"nprogress": "0.2.0",
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
"downvoted": "Downvoted",
|
||||
"views": "Views",
|
||||
"posters": "Posters",
|
||||
"watching": "Watching",
|
||||
"reputation": "Reputation",
|
||||
"lastpost": "Last post",
|
||||
"firstpost": "First post",
|
||||
|
||||
@@ -218,6 +218,8 @@ TopicObjectSlim:
|
||||
type: number
|
||||
postercount:
|
||||
type: number
|
||||
followercount:
|
||||
type: number
|
||||
scheduled:
|
||||
type: number
|
||||
deleted:
|
||||
|
||||
@@ -10,9 +10,10 @@ const plugins = require('../plugins');
|
||||
|
||||
const intFields = [
|
||||
'tid', 'cid', 'uid', 'mainPid', 'postcount',
|
||||
'viewcount', 'postercount', 'deleted', 'locked', 'pinned',
|
||||
'pinExpiry', 'timestamp', 'upvotes', 'downvotes', 'lastposttime',
|
||||
'deleterUid',
|
||||
'viewcount', 'postercount', 'followercount',
|
||||
'deleted', 'locked', 'pinned', 'pinExpiry',
|
||||
'timestamp', 'upvotes', 'downvotes',
|
||||
'lastposttime', 'deleterUid',
|
||||
];
|
||||
|
||||
module.exports = function (Topics) {
|
||||
|
||||
@@ -48,29 +48,30 @@ module.exports = function (Topics) {
|
||||
}
|
||||
|
||||
async function follow(tid, uid) {
|
||||
await addToSets(`tid:${tid}:followers`, `uid:${uid}:followed_tids`, tid, uid);
|
||||
await db.setAdd(`tid:${tid}:followers`, uid);
|
||||
await db.sortedSetAdd(`uid:${uid}:followed_tids`, Date.now(), tid);
|
||||
await updateFollowerCount(tid);
|
||||
}
|
||||
|
||||
async function unfollow(tid, uid) {
|
||||
await removeFromSets(`tid:${tid}:followers`, `uid:${uid}:followed_tids`, tid, uid);
|
||||
await db.setRemove(`tid:${tid}:followers`, uid);
|
||||
await db.sortedSetRemove(`uid:${uid}:followed_tids`, tid);
|
||||
await updateFollowerCount(tid);
|
||||
}
|
||||
|
||||
async function ignore(tid, uid) {
|
||||
await addToSets(`tid:${tid}:ignorers`, `uid:${uid}:ignored_tids`, tid, uid);
|
||||
await db.setAdd(`tid:${tid}:ignorers`, uid);
|
||||
await db.sortedSetAdd(`uid:${uid}:ignored_tids`, Date.now(), tid);
|
||||
}
|
||||
|
||||
async function unignore(tid, uid) {
|
||||
await removeFromSets(`tid:${tid}:ignorers`, `uid:${uid}:ignored_tids`, tid, uid);
|
||||
await db.setRemove(`tid:${tid}:ignorers`, uid);
|
||||
await db.sortedSetRemove(`uid:${uid}:ignored_tids`, tid);
|
||||
}
|
||||
|
||||
async function addToSets(set1, set2, tid, uid) {
|
||||
await db.setAdd(set1, uid);
|
||||
await db.sortedSetAdd(set2, Date.now(), tid);
|
||||
}
|
||||
|
||||
async function removeFromSets(set1, set2, tid, uid) {
|
||||
await db.setRemove(set1, uid);
|
||||
await db.sortedSetRemove(set2, tid);
|
||||
async function updateFollowerCount(tid) {
|
||||
const count = await db.setCount(`tid:${tid}:followers`);
|
||||
await Topics.setTopicField(tid, 'followercount', count);
|
||||
}
|
||||
|
||||
Topics.isFollowing = async function (tids, uid) {
|
||||
|
||||
@@ -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