From 9d4a9b83ccabb28da178bb041900d90a24951ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 29 Aug 2025 21:02:14 -0400 Subject: [PATCH] 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::pids causing that post to get stuck at the top of that zset, which led to the bug in this issue --- src/posts/edit.js | 4 +++- test/topics.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/posts/edit.js b/src/posts/edit.js index b18bf99078..0b8b6ff009 100644 --- a/src/posts/edit.js +++ b/src/posts/edit.js @@ -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; diff --git a/test/topics.js b/test/topics.js index bc92bbff09..eaae7d76c7 100644 --- a/test/topics.js +++ b/test/topics.js @@ -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::pids after editing and posting immediately', async () => { + const scheduleTimestamp = Date.now() + (86400000 * 365); + const result = await topics.post({ + cid: categoryObj.cid, + title: 'testing 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::pids should be less than Date.now() + const score = await db.sortedSetScore(`cid:${categoryObj.cid}:pids`, mainPid); + assert(score < Date.now(), 'Post in cid::pids has wrong score, it should not be in the future'); + }); }); });