闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
525 B

  1. # frozen_string_literal: true
  2. class ActivityTracker
  3. EXPIRE_AFTER = 90.days.seconds
  4. class << self
  5. def increment(prefix)
  6. key = [prefix, current_week].join(':')
  7. redis.incrby(key, 1)
  8. redis.expire(key, EXPIRE_AFTER)
  9. end
  10. def record(prefix, value)
  11. key = [prefix, current_week].join(':')
  12. redis.pfadd(key, value)
  13. redis.expire(key, EXPIRE_AFTER)
  14. end
  15. private
  16. def redis
  17. Redis.current
  18. end
  19. def current_week
  20. Time.zone.today.cweek
  21. end
  22. end
  23. end