From ec27db78bec4b50a475a5dd830bc0d695bfe66cd Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 8 Jan 2019 15:02:51 +0800 Subject: [PATCH] FIX: Set unique post key for a user outside of transaction. Previously, the Redis key was set within the transaction and the key isn't deleted if the transaction is not successful. Note that this isn't tested because we don't have a repro of what can raise an error within the transaction. https://meta.discourse.org/t/body-is-too-similar-to-what-you-previously-posted-even-when-previous-post-didnt-go-through/105436 --- lib/post_creator.rb | 2 +- spec/components/post_creator_spec.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 173a30cf20b..4c4c0793256 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -167,7 +167,6 @@ class PostCreator create_topic save_post extract_links - store_unique_post_key track_topic update_topic_stats update_topic_auto_close @@ -182,6 +181,7 @@ class PostCreator end if @post && errors.blank? && !@opts[:import_mode] + store_unique_post_key # update counters etc. @post.topic.reload diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 304491c59cc..8774c6402e9 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -580,8 +580,9 @@ describe PostCreator do it "returns blank for another post with the same content" do creator.create - new_post_creator.create - expect(new_post_creator.errors).to be_present + post = new_post_creator.create + + expect(post.errors[:raw]).to include(I18n.t(:just_posted_that)) end it "returns a post for admins" do