- ftl.internal,
- ftl.domain,
- MIN(ftl.user_id) AS user_id,
- SUM(clicks) AS clicks
- FROM topic_links AS ftl
- JOIN posts AS source_posts ON ftl.post_id = source_posts.id
- LEFT JOIN topics AS ft ON ftl.link_topic_id = ft.id
- LEFT JOIN categories AS c ON c.id = ft.category_id
- LEFT JOIN posts AS target_posts ON ftl.link_post_id = target_posts.id
- /*where*/
- GROUP BY ftl.url, ft.title, ftl.title, ftl.link_topic_id, ftl.reflection, ftl.internal, ftl.domain
- ORDER BY clicks DESC, count(*) DESC
- LIMIT 51
- SQL
- builder.where("ftl.topic_id = :topic_id", topic_id: topic_id)
- apply_source_post_visibility_filters(builder, guardian, source_post: "source_posts")
- apply_link_visibility_filters(
- builder,
- link: "ftl",
- target_topic: "ft",