global_follow_recommendations_v01.sql 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. SELECT
  2. account_id,
  3. sum(rank) AS rank,
  4. array_agg(reason) AS reason
  5. FROM (
  6. SELECT
  7. account_summaries.account_id AS account_id,
  8. count(follows.id) / (1.0 + count(follows.id)) AS rank,
  9. 'most_followed' AS reason
  10. FROM follows
  11. INNER JOIN account_summaries ON account_summaries.account_id = follows.target_account_id
  12. INNER JOIN users ON users.account_id = follows.account_id
  13. WHERE users.current_sign_in_at >= (now() - interval '30 days')
  14. AND account_summaries.sensitive = 'f'
  15. AND NOT EXISTS (SELECT 1 FROM follow_recommendation_suppressions WHERE follow_recommendation_suppressions.account_id = follows.target_account_id)
  16. GROUP BY account_summaries.account_id
  17. HAVING count(follows.id) >= 5
  18. UNION ALL
  19. SELECT account_summaries.account_id AS account_id,
  20. sum(status_stats.reblogs_count + status_stats.favourites_count) / (1.0 + sum(status_stats.reblogs_count + status_stats.favourites_count)) AS rank,
  21. 'most_interactions' AS reason
  22. FROM status_stats
  23. INNER JOIN statuses ON statuses.id = status_stats.status_id
  24. INNER JOIN account_summaries ON account_summaries.account_id = statuses.account_id
  25. WHERE statuses.id >= ((date_part('epoch', now() - interval '30 days') * 1000)::bigint << 16)
  26. AND account_summaries.sensitive = 'f'
  27. AND NOT EXISTS (SELECT 1 FROM follow_recommendation_suppressions WHERE follow_recommendation_suppressions.account_id = statuses.account_id)
  28. GROUP BY account_summaries.account_id
  29. HAVING sum(status_stats.reblogs_count + status_stats.favourites_count) >= 5
  30. ) t0
  31. GROUP BY account_id
  32. ORDER BY rank DESC