diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-04-20 18:06:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 18:06:40 +0200 |
commit | 97da7b73071e9f515c4bb0bca72c88d1a13b14aa (patch) | |
tree | 89c81064b9e3725962a847e98099a5b84b728733 /app/models/follow_recommendation.rb | |
parent | df326b8b5c0659edb2aca77690a892f228b0e099 (diff) | |
parent | 4b115d070c9a8b6082ed207bd0a14e809eded322 (diff) |
Merge pull request #1521 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models/follow_recommendation.rb')
-rw-r--r-- | app/models/follow_recommendation.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/follow_recommendation.rb b/app/models/follow_recommendation.rb new file mode 100644 index 000000000..c4355224d --- /dev/null +++ b/app/models/follow_recommendation.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true +# == Schema Information +# +# Table name: follow_recommendations +# +# account_id :bigint(8) primary key +# rank :decimal(, ) +# reason :text is an Array +# + +class FollowRecommendation < ApplicationRecord + self.primary_key = :account_id + + belongs_to :account_summary, foreign_key: :account_id + belongs_to :account, foreign_key: :account_id + + scope :safe, -> { joins(:account_summary).merge(AccountSummary.safe) } + scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) } + scope :filtered, -> { joins(:account_summary).merge(AccountSummary.filtered) } + + def readonly? + true + end + + def self.get(account, limit, exclude_account_ids = []) + account_ids = Redis.current.zrevrange("follow_recommendations:#{account.user_locale}", 0, -1).map(&:to_i) - exclude_account_ids - [account.id] + + return [] if account_ids.empty? || limit < 1 + + accounts = Account.followable_by(account) + .not_excluded_by_account(account) + .not_domain_blocked_by_account(account) + .where(id: account_ids) + .limit(limit) + .index_by(&:id) + + account_ids.map { |id| accounts[id] }.compact + end +end |