mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix: wront topic events showing up in topic
when you perform a topic action on a topic that has queued posts store topic event id in the event hash dont load queued post events when adding a new topic event
This commit is contained in:
@@ -104,10 +104,10 @@
|
||||
"nodebb-plugin-ntfy": "1.7.4",
|
||||
"nodebb-plugin-spam-be-gone": "2.2.2",
|
||||
"nodebb-rewards-essentials": "1.0.0",
|
||||
"nodebb-theme-harmony": "1.2.61",
|
||||
"nodebb-theme-harmony": "1.2.62",
|
||||
"nodebb-theme-lavender": "7.1.8",
|
||||
"nodebb-theme-peace": "2.2.5",
|
||||
"nodebb-theme-persona": "13.3.23",
|
||||
"nodebb-theme-peace": "2.2.6",
|
||||
"nodebb-theme-persona": "13.3.24",
|
||||
"nodebb-widget-essentials": "7.0.16",
|
||||
"nodemailer": "6.9.13",
|
||||
"nprogress": "0.2.0",
|
||||
|
||||
@@ -120,7 +120,11 @@ Events.get = async (tid, uid, reverse = false) => {
|
||||
const timestamps = eventIds.map(obj => obj.score);
|
||||
eventIds = eventIds.map(obj => obj.value);
|
||||
let events = await db.getObjects(keys);
|
||||
events = await modifyEvent({ tid, uid, eventIds, timestamps, events });
|
||||
events.forEach((e, idx) => {
|
||||
e.timestamp = timestamps[idx];
|
||||
});
|
||||
await addEventsFromPostQueue(tid, uid, events);
|
||||
events = await modifyEvent({ uid, events });
|
||||
if (reverse) {
|
||||
events.reverse();
|
||||
}
|
||||
@@ -144,8 +148,7 @@ async function getCategoryInfo(cids) {
|
||||
return _.zipObject(uniqCids, catData);
|
||||
}
|
||||
|
||||
async function modifyEvent({ tid, uid, eventIds, timestamps, events }) {
|
||||
// Add posts from post queue
|
||||
async function addEventsFromPostQueue(tid, uid, events) {
|
||||
const isPrivileged = await user.isPrivileged(uid);
|
||||
if (isPrivileged) {
|
||||
const queuedPosts = await posts.getQueuedPosts({ tid }, { metadata: false });
|
||||
@@ -155,11 +158,10 @@ async function modifyEvent({ tid, uid, eventIds, timestamps, events }) {
|
||||
timestamp: item.data.timestamp || Date.now(),
|
||||
uid: item.data.uid,
|
||||
})));
|
||||
queuedPosts.forEach((item) => {
|
||||
timestamps.push(item.data.timestamp || Date.now());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function modifyEvent({ uid, events }) {
|
||||
const [users, fromCategories, userSettings] = await Promise.all([
|
||||
getUserInfo(events.map(event => event.uid).filter(Boolean)),
|
||||
getCategoryInfo(events.map(event => event.fromCid).filter(Boolean)),
|
||||
@@ -183,10 +185,8 @@ async function modifyEvent({ tid, uid, eventIds, timestamps, events }) {
|
||||
events = events.filter(event => Events._types.hasOwnProperty(event.type));
|
||||
|
||||
// Add user & metadata
|
||||
events.forEach((event, idx) => {
|
||||
event.id = parseInt(eventIds[idx], 10);
|
||||
event.timestamp = timestamps[idx];
|
||||
event.timestampISO = new Date(timestamps[idx]).toISOString();
|
||||
events.forEach((event) => {
|
||||
event.timestampISO = utils.toISOString(event.timestamp);
|
||||
if (event.hasOwnProperty('uid')) {
|
||||
event.user = users.get(event.uid === 'system' ? 'system' : parseInt(event.uid, 10));
|
||||
}
|
||||
@@ -221,16 +221,15 @@ Events.log = async (tid, payload) => {
|
||||
}
|
||||
|
||||
const eventId = await db.incrObjectField('global', 'nextTopicEventId');
|
||||
payload.id = eventId;
|
||||
|
||||
await Promise.all([
|
||||
db.setObject(`topicEvent:${eventId}`, payload),
|
||||
db.sortedSetAdd(`topic:${tid}:events`, timestamp, eventId),
|
||||
]);
|
||||
|
||||
payload.timestamp = timestamp;
|
||||
let events = await modifyEvent({
|
||||
uid: payload.uid,
|
||||
eventIds: [eventId],
|
||||
timestamps: [timestamp],
|
||||
events: [payload],
|
||||
});
|
||||
|
||||
|
||||
38
src/upgrades/3.8.3/topic-event-ids.js
Normal file
38
src/upgrades/3.8.3/topic-event-ids.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Add id field to all topic events',
|
||||
timestamp: Date.UTC(2024, 5, 24),
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
|
||||
let nextId = await db.getObjectField('global', 'nextTopicEventId');
|
||||
nextId = parseInt(nextId, 10) || 0;
|
||||
const ids = [];
|
||||
for (let i = 1; i < nextId; i++) {
|
||||
ids.push(i);
|
||||
}
|
||||
await batch.processArray(ids, async (eids) => {
|
||||
const eventData = await db.getObjects(eids.map(eid => `topicEvent:${eid}`));
|
||||
const bulkSet = [];
|
||||
eventData.forEach((event, idx) => {
|
||||
if (event && event.type) {
|
||||
const id = eids[idx];
|
||||
bulkSet.push(
|
||||
[`topicEvent:${id}`, { id: id }]
|
||||
);
|
||||
}
|
||||
});
|
||||
await db.setObjectBulk(bulkSet);
|
||||
progress.incr(eids.length);
|
||||
}, {
|
||||
batch: 500,
|
||||
progress,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user