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.

43 lines
908 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. pairs = statuses.reverse_each.lazy.reject(&method(:status_filtered?)).map(&method(:process_status)).to_a
  12. redis.pipelined do
  13. redis.zadd(account_home_key, pairs) if pairs.any?
  14. redis.del("account:#{@account.id}:regeneration")
  15. end
  16. end
  17. def process_status(status)
  18. [status.id, status.reblog? ? status.reblog_of_id : status.id]
  19. end
  20. def status_filtered?(status)
  21. FeedManager.instance.filter?(:home, status, account.id)
  22. end
  23. def account_home_key
  24. FeedManager.instance.key(:home, account.id)
  25. end
  26. def statuses
  27. Status.as_home_timeline(account).order(account_id: :desc).limit(LIMIT)
  28. end
  29. def redis
  30. Redis.current
  31. end
  32. end