Move AccountSuggestions::Source subclasses default limit value to constant (#29282)

This commit is contained in:
Matt Jankowski 2024-02-20 04:21:49 -05:00 committed by GitHub
parent e1cee84e58
commit 0ef44ee720
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 6 additions and 4 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
def get(account, limit: 10) def get(account, limit: DEFAULT_LIMIT)
Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, key] } Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, key] }
WITH first_degree AS ( WITH first_degree AS (
SELECT target_account_id SELECT target_account_id

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccountSuggestions::GlobalSource < AccountSuggestions::Source class AccountSuggestions::GlobalSource < AccountSuggestions::Source
def get(account, limit: 10) def get(account, limit: DEFAULT_LIMIT)
FollowRecommendation.localized(content_locale).joins(:account).merge(base_account_scope(account)).order(rank: :desc).limit(limit).pluck(:account_id, :reason) FollowRecommendation.localized(content_locale).joins(:account).merge(base_account_scope(account)).order(rank: :desc).limit(limit).pluck(:account_id, :reason)
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccountSuggestions::SettingSource < AccountSuggestions::Source class AccountSuggestions::SettingSource < AccountSuggestions::Source
def get(account, limit: 10) def get(account, limit: DEFAULT_LIMIT)
if setting_enabled? if setting_enabled?
base_account_scope(account).where(setting_to_where_condition).limit(limit).pluck(:id).zip([key].cycle) base_account_scope(account).where(setting_to_where_condition).limit(limit).pluck(:id).zip([key].cycle)
else else

View file

@ -47,7 +47,7 @@ class AccountSuggestions::SimilarProfilesSource < AccountSuggestions::Source
end end
end end
def get(account, limit: 10) def get(account, limit: DEFAULT_LIMIT)
recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id) recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id)
if Chewy.enabled? && !recently_followed_account_ids.empty? if Chewy.enabled? && !recently_followed_account_ids.empty?

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccountSuggestions::Source class AccountSuggestions::Source
DEFAULT_LIMIT = 10
def get(_account, **kwargs) def get(_account, **kwargs)
raise NotImplementedError raise NotImplementedError
end end