about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-12-30 17:20:07 -0600
committerDavid Yip <yipdw@member.fsf.org>2017-12-30 17:20:07 -0600
commit4cca1d1e7efce51eecb64489f412a7b8631f0aed (patch)
tree5259571423a25c9a478052599c5e3d04db7fc8bd /app/lib
parente4944d065b6bd6c6718c27700971be832ed4861a (diff)
parentf4b80e6511f21b60f71ed182bb66ca6ef0ba9f66 (diff)
Merge remote-tracking branch 'origin/master' into merge-upstream
 Conflicts:
	app/controllers/auth/confirmations_controller.rb
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activity_tracker.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/lib/activity_tracker.rb b/app/lib/activity_tracker.rb
new file mode 100644
index 000000000..50e927b0c
--- /dev/null
+++ b/app/lib/activity_tracker.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class ActivityTracker
+  EXPIRE_AFTER = 90.days.seconds
+
+  class << self
+    def increment(prefix)
+      key = [prefix, current_week].join(':')
+
+      redis.incrby(key, 1)
+      redis.expire(key, EXPIRE_AFTER)
+    end
+
+    def record(prefix, value)
+      key = [prefix, current_week].join(':')
+
+      redis.pfadd(key, value)
+      redis.expire(key, value)
+    end
+
+    private
+
+    def redis
+      Redis.current
+    end
+
+    def current_week
+      Time.zone.today.cweek
+    end
+  end
+end