diff --git a/app/models/post.rb b/app/models/post.rb index 93944b4a9..045bb5574 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1267,9 +1267,7 @@ class Post < ApplicationRecord end def set_count_in_cache(tags, count, expiry = nil) - if expiry.nil? - [count.seconds, 20.hours].min - end + expiry ||= [count.seconds, 20.hours].min Cache.put(count_cache_key(tags), count, expiry) end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 91e41a302..396324198 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2555,6 +2555,11 @@ class PostTest < ActiveSupport::TestCase should "return the true count, if not cached" do assert_equal(1, Post.fast_count("aaa score:42")) end + + should "set the expiration time" do + Cache.expects(:put).with(Post.count_cache_key("aaa score:42"), 1, 1) + Post.fast_count("aaa score:42") + end end context "a blank search" do