闭社主体 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.

29 lines
506 B

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