Post#fast_count: fix cache expiry not being set (#3925).
This commit is contained in:
@@ -1267,9 +1267,7 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_count_in_cache(tags, count, expiry = nil)
|
def set_count_in_cache(tags, count, expiry = nil)
|
||||||
if expiry.nil?
|
expiry ||= [count.seconds, 20.hours].min
|
||||||
[count.seconds, 20.hours].min
|
|
||||||
end
|
|
||||||
|
|
||||||
Cache.put(count_cache_key(tags), count, expiry)
|
Cache.put(count_cache_key(tags), count, expiry)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2555,6 +2555,11 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
should "return the true count, if not cached" do
|
should "return the true count, if not cached" do
|
||||||
assert_equal(1, Post.fast_count("aaa score:42"))
|
assert_equal(1, Post.fast_count("aaa score:42"))
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "a blank search" do
|
context "a blank search" do
|
||||||
|
|||||||
Reference in New Issue
Block a user