Skip to content

Conversation

ClearlyClaire
Copy link
Contributor

@ClearlyClaire ClearlyClaire commented Dec 19, 2023

Note that I am not too sure about the performance implications of this implementation.

Alternatively, we could have the following:

    Account.find_by_sql([<<~SQL.squish, { id: account.id, limit: limit }]).map { |row| [row.id, key] }
      WITH first_degree AS (
          SELECT target_account_id AS id, target_accounts.hide_collections AS hide_collections
          FROM follows
          JOIN accounts AS target_accounts ON follows.target_account_id = target_accounts.id
          WHERE account_id = :id
            AND NOT target_accounts.hide_collections
      )
      SELECT accounts.id, COUNT(*) AS frequency
      FROM accounts
      JOIN follows ON follows.target_account_id = accounts.id
      JOIN account_stats ON account_stats.account_id = accounts.id
      LEFT OUTER JOIN follow_recommendation_mutes ON follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id
      WHERE follows.account_id IN (SELECT id FROM first_degree WHERE NOT hide_collections)
        AND follows.target_account_id NOT IN (SELECT id FROM first_degree)
        AND follows.target_account_id <> :id
        AND accounts.discoverable
        AND accounts.suspended_at IS NULL
        AND accounts.silenced_at IS NULL
        AND accounts.moved_to_account_id IS NULL
        AND follow_recommendation_mutes.target_account_id IS NULL
      GROUP BY accounts.id, account_stats.id
      ORDER BY frequency DESC, account_stats.followers_count ASC
      LIMIT :limit
    SQL

@ClearlyClaire ClearlyClaire added the bug Something isn't working label Dec 19, 2023
@renchap renchap requested a review from Gargron December 19, 2023 14:35
@vmstan
Copy link
Contributor

vmstan commented Dec 19, 2023

Came to suggest this. 😄

@Gargron Gargron added this pull request to the merge queue Dec 20, 2023
Merged via the queue into main with commit d29b1cc Dec 20, 2023
@Gargron Gargron deleted the fixes/friend-of-friend branch December 20, 2023 14:41
vmstan pushed a commit to vmstan/mastodon that referenced this pull request Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants