From 2ae7ec42df5e29e35fe79be59a900e530c1e3bc8 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 1 Oct 2018 10:38:15 -0500 Subject: [PATCH] Post#fast_count: raise min cache lifetime to 3 minutes (#3925). --- app/models/post.rb | 2 +- test/unit/post_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 045bb5574..f45770b3d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1267,7 +1267,7 @@ class Post < ApplicationRecord end def set_count_in_cache(tags, count, expiry = nil) - expiry ||= [count.seconds, 20.hours].min + expiry ||= count.seconds.clamp(3.minutes, 20.hours).to_i Cache.put(count_cache_key(tags), count, expiry) end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 396324198..b3089c108 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2557,7 +2557,7 @@ class PostTest < ActiveSupport::TestCase end should "set the expiration time" do - Cache.expects(:put).with(Post.count_cache_key("aaa score:42"), 1, 1) + Cache.expects(:put).with(Post.count_cache_key("aaa score:42"), 1, 180) Post.fast_count("aaa score:42") end end