mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #12652, incorrect user, post, topic counters with AP enabled
This commit is contained in:
@@ -10,6 +10,7 @@ const notifications = require('../notifications');
|
||||
const plugins = require('../plugins');
|
||||
const flags = require('../flags');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
Posts.delete = async function (pid, uid) {
|
||||
@@ -108,7 +109,8 @@ module.exports = function (Posts) {
|
||||
});
|
||||
await db.sortedSetRemoveBulk(bulkRemove);
|
||||
|
||||
const incrObjectBulk = [['global', { postCount: -postData.length }]];
|
||||
const localCount = postData.filter(p => utils.isNumber(p.pid)).length;
|
||||
const incrObjectBulk = [['global', { postCount: -localCount }]];
|
||||
|
||||
const postsByCategory = _.groupBy(postData, p => parseInt(p.cid, 10));
|
||||
for (const [cid, posts] of Object.entries(postsByCategory)) {
|
||||
|
||||
@@ -67,7 +67,7 @@ module.exports = function (Topics) {
|
||||
db.sortedSetsAdd(countedSortedSetKeys, 0, topicData.tid),
|
||||
user.addTopicIdToUser(topicData.uid, topicData.tid, timestamp),
|
||||
db.incrObjectField(`category:${topicData.cid}`, 'topic_count'),
|
||||
db.incrObjectField('global', 'topicCount'),
|
||||
utils.isNumber(tid) ? db.incrObjectField('global', 'topicCount') : null,
|
||||
Topics.createTags(data.tags, topicData.tid, timestamp),
|
||||
scheduled ? Promise.resolve() : categories.updateRecentTid(topicData.cid, topicData.tid),
|
||||
]);
|
||||
|
||||
@@ -8,7 +8,7 @@ const categories = require('../categories');
|
||||
const flags = require('../flags');
|
||||
const plugins = require('../plugins');
|
||||
const batch = require('../batch');
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (Topics) {
|
||||
Topics.delete = async function (tid, uid) {
|
||||
@@ -140,7 +140,9 @@ module.exports = function (Topics) {
|
||||
|
||||
async function reduceCounters(tid) {
|
||||
const incr = -1;
|
||||
if (utils.isNumber(tid)) {
|
||||
await db.incrObjectFieldBy('global', 'topicCount', incr);
|
||||
}
|
||||
const topicData = await Topics.getTopicFields(tid, ['cid', 'postcount']);
|
||||
const postCountChange = incr * topicData.postcount;
|
||||
await Promise.all([
|
||||
|
||||
21
src/upgrades/4.0.0/fix_global_user_and_post_counts.js
Normal file
21
src/upgrades/4.0.0/fix_global_user_and_post_counts.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const meta = require('../../meta');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix global counts for users and posts due to faulty AP logic',
|
||||
timestamp: Date.UTC(2024, 5, 25),
|
||||
method: async () => {
|
||||
if (!meta.config.activitypubEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const counts = await db.sortedSetsCard(['users:joindate', 'posts:pid', 'topics:tid']);
|
||||
await db.setObject('global', {
|
||||
userCount: counts[0],
|
||||
postCount: counts[1],
|
||||
topicCount: counts[2],
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -142,7 +142,7 @@ module.exports = function (User) {
|
||||
|
||||
await Promise.all([
|
||||
db.sortedSetRemoveBulk(bulkRemove),
|
||||
db.decrObjectField('global', 'userCount'),
|
||||
utils.isNumber(uid) ? db.decrObjectField('global', 'userCount') : null,
|
||||
db.deleteAll(keys),
|
||||
db.setRemove('invitation:uids', uid),
|
||||
deleteUserIps(uid),
|
||||
|
||||
Reference in New Issue
Block a user