mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +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-spam-be-gone": "2.3.1",
|
||||||
"nodebb-plugin-web-push": "0.7.3",
|
"nodebb-plugin-web-push": "0.7.3",
|
||||||
"nodebb-rewards-essentials": "1.0.1",
|
"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-lavender": "7.1.18",
|
||||||
"nodebb-theme-peace": "2.2.39",
|
"nodebb-theme-peace": "2.2.40",
|
||||||
"nodebb-theme-persona": "14.1.5",
|
"nodebb-theme-persona": "14.1.6",
|
||||||
"nodebb-widget-essentials": "7.0.36",
|
"nodebb-widget-essentials": "7.0.36",
|
||||||
"nodemailer": "6.10.0",
|
"nodemailer": "6.10.0",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
"downvoted": "Downvoted",
|
"downvoted": "Downvoted",
|
||||||
"views": "Views",
|
"views": "Views",
|
||||||
"posters": "Posters",
|
"posters": "Posters",
|
||||||
|
"watching": "Watching",
|
||||||
"reputation": "Reputation",
|
"reputation": "Reputation",
|
||||||
"lastpost": "Last post",
|
"lastpost": "Last post",
|
||||||
"firstpost": "First post",
|
"firstpost": "First post",
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ TopicObjectSlim:
|
|||||||
type: number
|
type: number
|
||||||
postercount:
|
postercount:
|
||||||
type: number
|
type: number
|
||||||
|
followercount:
|
||||||
|
type: number
|
||||||
scheduled:
|
scheduled:
|
||||||
type: number
|
type: number
|
||||||
deleted:
|
deleted:
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ const plugins = require('../plugins');
|
|||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
'tid', 'cid', 'uid', 'mainPid', 'postcount',
|
'tid', 'cid', 'uid', 'mainPid', 'postcount',
|
||||||
'viewcount', 'postercount', 'deleted', 'locked', 'pinned',
|
'viewcount', 'postercount', 'followercount',
|
||||||
'pinExpiry', 'timestamp', 'upvotes', 'downvotes', 'lastposttime',
|
'deleted', 'locked', 'pinned', 'pinExpiry',
|
||||||
'deleterUid',
|
'timestamp', 'upvotes', 'downvotes',
|
||||||
|
'lastposttime', 'deleterUid',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
|
|||||||
@@ -48,29 +48,30 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function follow(tid, uid) {
|
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) {
|
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) {
|
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) {
|
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) {
|
async function updateFollowerCount(tid) {
|
||||||
await db.setAdd(set1, uid);
|
const count = await db.setCount(`tid:${tid}:followers`);
|
||||||
await db.sortedSetAdd(set2, Date.now(), tid);
|
await Topics.setTopicField(tid, 'followercount', count);
|
||||||
}
|
|
||||||
|
|
||||||
async function removeFromSets(set1, set2, tid, uid) {
|
|
||||||
await db.setRemove(set1, uid);
|
|
||||||
await db.sortedSetRemove(set2, tid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.isFollowing = async function (tids, uid) {
|
Topics.isFollowing = async function (tids, uid) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const crypto = require('crypto');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Normalize topic thumbnails, post & user uploads to same format',
|
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 () {
|
method: async function () {
|
||||||
const { progress } = this;
|
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