From d956ca9cf7c46a49e2446521ede1aa23dd5cbcbf Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 7 Mar 2014 08:23:15 +0100 Subject: [PATCH] Be more liberal when the similar content of the post to be saved turns out to be the same post - instead of setting a random number, we actually store the post id in redis now - and when checking for matching recent post and it is the same, we allow it still Fixes the issue that we prevent a user from reverting to a previous state within the unique_posts_min time window. --- app/models/post.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 6f92b08fee6..98748ffc34a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -101,12 +101,13 @@ class Post < ActiveRecord::Base def store_unique_post_key if SiteSetting.unique_posts_mins > 0 - $redis.setex(unique_post_key, SiteSetting.unique_posts_mins.minutes.to_i, "1") + $redis.setex(unique_post_key, SiteSetting.unique_posts_mins.minutes.to_i, id) end end def matches_recent_post? - $redis.exists(unique_post_key) + post_id = $redis.get(unique_post_key) + post_id != nil and post_id != id end def raw_hash