logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

activity_tracker.rb (525B)


  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