From c1a01b2a28aed3f0199213c9622220a6ec063b04 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 19 Jul 2016 10:55:35 +1000 Subject: [PATCH] PERF: limit maximum number of topic links to 50 When a giant topic has huge numbers of links only show top 50 if expanded from the show more links... button. --- app/models/topic_link.rb | 31 +++++++++++++++++-------------- config/locales/client.en.yml | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index 2f7cc745236..182c3d64d91 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -37,20 +37,23 @@ class TopicLink < ActiveRecord::Base def self.topic_map(guardian, topic_id) # Sam: complicated reports are really hard in AR - builder = SqlBuilder.new("SELECT ftl.url, - COALESCE(ft.title, ftl.title) AS title, - ftl.link_topic_id, - ftl.reflection, - ftl.internal, - ftl.domain, - MIN(ftl.user_id) AS user_id, - SUM(clicks) AS clicks - FROM topic_links AS ftl - LEFT JOIN topics AS ft ON ftl.link_topic_id = ft.id - LEFT JOIN categories AS c ON c.id = ft.category_id - /*where*/ - GROUP BY ftl.url, ft.title, ftl.title, ftl.link_topic_id, ftl.reflection, ftl.internal, ftl.domain - ORDER BY clicks DESC") + builder = SqlBuilder.new <