potential_friendship_tracker.rb 688 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. class PotentialFriendshipTracker
  3. EXPIRE_AFTER = 90.days.seconds
  4. MAX_ITEMS = 80
  5. WEIGHTS = {
  6. reply: 1,
  7. favourite: 10,
  8. reblog: 20,
  9. }.freeze
  10. class << self
  11. include Redisable
  12. def record(account_id, target_account_id, action)
  13. return if account_id == target_account_id
  14. key = "interactions:#{account_id}"
  15. weight = WEIGHTS[action]
  16. redis.zincrby(key, weight, target_account_id)
  17. redis.zremrangebyrank(key, 0, -MAX_ITEMS)
  18. redis.expire(key, EXPIRE_AFTER)
  19. end
  20. def remove(account_id, target_account_id)
  21. redis.zrem("interactions:#{account_id}", target_account_id)
  22. end
  23. end
  24. end