This repository has been archived on 2024-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-12 06:37:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FollowRecommendationFilter
|
2022-04-28 11:47:34 -04:00
|
|
|
include Redisable
|
|
|
|
|
2021-04-12 06:37:14 -04:00
|
|
|
KEYS = %i(
|
|
|
|
language
|
|
|
|
status
|
|
|
|
).freeze
|
|
|
|
|
|
|
|
attr_reader :params, :language
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@language = params.delete('language') || I18n.locale
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def results
|
|
|
|
if params['status'] == 'suppressed'
|
|
|
|
Account.joins(:follow_recommendation_suppression).order(FollowRecommendationSuppression.arel_table[:id].desc).to_a
|
|
|
|
else
|
2022-04-28 11:47:34 -04:00
|
|
|
account_ids = redis.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i)
|
2021-04-12 06:37:14 -04:00
|
|
|
accounts = Account.where(id: account_ids).index_by(&:id)
|
|
|
|
|
2023-05-23 04:49:12 -04:00
|
|
|
account_ids.filter_map { |id| accounts[id] }
|
2021-04-12 06:37:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|