]> cat aescling's git repositories - mastodon.git/blob - app/lib/activity_tracker.rb
Guard against nil URLs in Request class (#7284)
[mastodon.git] / app / lib / activity_tracker.rb
1 # frozen_string_literal: true
2
3 class ActivityTracker
4 EXPIRE_AFTER = 90.days.seconds
5
6 class << self
7 def increment(prefix)
8 key = [prefix, current_week].join(':')
9
10 redis.incrby(key, 1)
11 redis.expire(key, EXPIRE_AFTER)
12 end
13
14 def record(prefix, value)
15 key = [prefix, current_week].join(':')
16
17 redis.pfadd(key, value)
18 redis.expire(key, EXPIRE_AFTER)
19 end
20
21 private
22
23 def redis
24 Redis.current
25 end
26
27 def current_week
28 Time.zone.today.cweek
29 end
30 end
31 end
This page took 0.066844 seconds and 4 git commands to generate.