44class DownvotedCommenters
55 include IntervalHelper
66
7- CACHE_TIME = 30 . minutes
7+ attr_reader :interval , :period , :cache_time
88
9- attr_reader :interval , :period
10-
11- def initialize ( interval )
9+ def initialize ( interval , cache_time = 30 . minutes )
1210 @interval = interval
11+ @cache_time = cache_time
1312 length = time_interval ( interval )
1413 @period = length [ :dur ] . send ( length [ :intv ] . downcase ) . ago
1514 end
@@ -20,7 +19,7 @@ def check_list_for(showing_user)
2019
2120 # aggregates for all commenters; not just those receiving downvotes
2221 def aggregates
23- Rails . cache . fetch ( "aggregates_#{ interval } " , expires_in : CACHE_TIME ) {
22+ Rails . cache . fetch ( "aggregates_#{ interval } _ #{ cache_time } " , expires_in : self . cache_time ) {
2423 ActiveRecord ::Base . connection . exec_query ( "
2524 select
2625 stddev(sum_downvotes) as stddev,
@@ -52,7 +51,8 @@ def avg_sum_downvotes
5251 end
5352
5453 def commenters
55- Rails . cache . fetch ( "downvoted_commenters_#{ interval } " , expires_in : CACHE_TIME ) {
54+ Rails . cache . fetch ( "downvoted_commenters_#{ interval } _#{ cache_time } " ,
55+ expires_in : self . cache_time ) {
5656 rank = 0
5757 User . active . joins ( :comments )
5858 . where ( "comments.created_at >= ?" , period )
0 commit comments