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.
This commit is contained in:
Sam 2016-07-19 10:55:35 +10:00
parent a5d0e0f277
commit c1a01b2a28
2 changed files with 18 additions and 15 deletions

View File

@ -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 <<SQL
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, count(*) DESC
LIMIT 50
SQL
builder.where('ftl.topic_id = :topic_id', topic_id: topic_id)
builder.where('ft.deleted_at IS NULL')

View File

@ -1868,7 +1868,7 @@ en:
title: "Topic Summary"
participants_title: "Frequent Posters"
links_title: "Popular Links"
links_shown: "show all {{totalLinks}} links..."
links_shown: "show more links..."
clicks:
one: "1 click"
other: "%{count} clicks"