1
0

follow_recommendations_v02.sql 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  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. LEFT OUTER JOIN follow_recommendation_suppressions ON follow_recommendation_suppressions.account_id = follows.target_account_id
  14. WHERE users.current_sign_in_at >= (now() - interval '30 days')
  15. AND account_summaries.sensitive = 'f'
  16. AND follow_recommendation_suppressions.id IS NULL
  17. GROUP BY account_summaries.account_id
  18. HAVING count(follows.id) >= 5
  19. UNION ALL
  20. SELECT account_summaries.account_id AS account_id,
  21. sum(status_stats.reblogs_count + status_stats.favourites_count) / (1.0 + sum(status_stats.reblogs_count + status_stats.favourites_count)) AS rank,
  22. 'most_interactions' AS reason
  23. FROM status_stats
  24. INNER JOIN statuses ON statuses.id = status_stats.status_id
  25. INNER JOIN account_summaries ON account_summaries.account_id = statuses.account_id
  26. LEFT OUTER JOIN follow_recommendation_suppressions ON follow_recommendation_suppressions.account_id = statuses.account_id
  27. WHERE statuses.id >= ((date_part('epoch', now() - interval '30 days') * 1000)::bigint << 16)
  28. AND account_summaries.sensitive = 'f'
  29. AND follow_recommendation_suppressions.id IS NULL
  30. GROUP BY account_summaries.account_id
  31. HAVING sum(status_stats.reblogs_count + status_stats.favourites_count) >= 5
  32. ) t0
  33. GROUP BY account_id
  34. ORDER BY rank DESC