mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: closes #13624, update post fields before schedule code
tldr when reschedule was called it was still using the timestamp in the future when adding to cid:<cid>:pids causing that post to get stuck at the top of that zset, which led to the bug in this issue
This commit is contained in:
@@ -49,12 +49,14 @@ module.exports = function (Posts) {
|
||||
uid: data.uid,
|
||||
});
|
||||
|
||||
// needs to be before editMainPost, otherwise scheduled topics use wrong timestamp
|
||||
await Posts.setPostFields(data.pid, result.post);
|
||||
|
||||
const [editor, topic] = await Promise.all([
|
||||
user.getUserFields(data.uid, ['username', 'userslug']),
|
||||
editMainPost(data, postData, topicData),
|
||||
]);
|
||||
|
||||
await Posts.setPostFields(data.pid, result.post);
|
||||
const contentChanged = ((data.sourceContent || data.content) !== oldContent) ||
|
||||
topic.renamed ||
|
||||
topic.tagsupdated;
|
||||
|
||||
@@ -2506,6 +2506,35 @@ describe('Topic\'s', () => {
|
||||
const score = await db.sortedSetScore('topics:scheduled', topicData.tid);
|
||||
assert(!score);
|
||||
});
|
||||
|
||||
it('should properly update timestamp in cid:<cid>:pids after editing and posting immediately', async () => {
|
||||
const scheduleTimestamp = Date.now() + (86400000 * 365);
|
||||
const result = await topics.post({
|
||||
cid: categoryObj.cid,
|
||||
title: 'testing cid:<cid>:pids',
|
||||
content: 'some content here',
|
||||
uid: adminUid,
|
||||
timestamp: scheduleTimestamp,
|
||||
});
|
||||
const { mainPid } = result.topicData;
|
||||
|
||||
assert.strictEqual(
|
||||
await db.isSortedSetMember(`cid:${categoryObj.cid}:pids`, mainPid),
|
||||
false,
|
||||
);
|
||||
|
||||
// edit main post and publish
|
||||
await posts.edit({
|
||||
uid: adminUid,
|
||||
pid: mainPid,
|
||||
content: 'some content here - edited',
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
// the score in cid:<cid>:pids should be less than Date.now()
|
||||
const score = await db.sortedSetScore(`cid:${categoryObj.cid}:pids`, mainPid);
|
||||
assert(score < Date.now(), 'Post in cid:<cid>:pids has wrong score, it should not be in the future');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user