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.

48 lines
947 B

  1. # frozen_string_literal: true
  2. class PrecomputeFeedService < BaseService
  3. LIMIT = FeedManager::MAX_ITEMS / 4
  4. def call(account)
  5. @account = account
  6. populate_feed
  7. end
  8. private
  9. attr_reader :account
  10. def populate_feed
  11. redis.pipelined do
  12. statuses.each do |status|
  13. process_status(status)
  14. end
  15. redis.del("account:#{@account.id}:regeneration")
  16. end
  17. end
  18. def process_status(status)
  19. add_status_to_feed(status) unless status_filtered?(status)
  20. end
  21. def add_status_to_feed(status)
  22. redis.zadd(account_home_key, status.id, status.reblog? ? status.reblog_of_id : status.id)
  23. end
  24. def status_filtered?(status)
  25. FeedManager.instance.filter?(:home, status, account.id)
  26. end
  27. def account_home_key
  28. FeedManager.instance.key(:home, account.id)
  29. end
  30. def statuses
  31. Status.as_home_timeline(account).order(account_id: :desc).limit(LIMIT)
  32. end
  33. def redis
  34. Redis.current
  35. end
  36. end