Skip to content

Commit

Permalink
update to default recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
jtomchak committed Nov 2, 2023
1 parent 4536ee1 commit fd5e823
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/services/follow_recommendations_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Returns an array of string user handles (eg: johndoe@mastodon.server) with follow recommendations
# for the provided user, according to other users that are the most followed by their existing follows.
class FollowRecommendationsService < BaseService
# We're making the assumption that these 3 accounts below exist in the local server and they
# represent the moth.social staff. Please keep this list up to date!
DEFAULT_FOLLOW_LIST = %w(mark bart misspurple).freeze
MAX_RESULTS = 50
DEFAULT_FOLLOW_LIMIT = 200

Expand All @@ -25,8 +22,8 @@ def call(handle:, limit: DEFAULT_FOLLOW_LIMIT, force: false)
Rails.cache.fetch(cache_key, expires_in: 6.months, force: force) do
direct_follows = account_follows(@handle).map(&:symbolize_keys)
if direct_follows.empty?
Rails.logger.info("No follows found for #{@handle}, defaulting to `DEFAULT_FOLLOW_LIST`")
direct_follows = generate_default_follows.map(&:symbolize_keys)
Rails.logger.info("No follows found for #{@handle}, defaulting to `Onboarding recommendations accounts list`")
return generate_default_follows.map(&:symbolize_keys).pluck(:acct)
end
direct_follow_ids = Set.new(direct_follows.pluck(:acct))
direct_follow_ids.add(@handle.sub(/^@/, ''))
Expand Down Expand Up @@ -84,9 +81,10 @@ def build_follow_graph(indirect_follows, direct_follow_ids)
end

# Returns an array of default follows in the same JSON format as the public API using AccountSerializer
#
def generate_default_follows
# domain: nil makes sure we're looking for local accounts
accounts = Account.where(username: DEFAULT_FOLLOW_LIST, domain: nil)
accounts = OnboardingAccountRecommendationsService.new.call
serializer = ActiveModel::Serializer::CollectionSerializer.new(
accounts, serializer: REST::AccountSerializer
)
Expand Down

0 comments on commit fd5e823

Please sign in to comment.