PERF: N+1 when generating not found page.

This commit is contained in:
Guo Xiang Tan 2017-09-28 15:07:09 +08:00
parent d36d5ba8ac
commit 373fd8990e

View File

@ -592,7 +592,7 @@ class ApplicationController < ActionController::Base
category_topic_ids = Category.pluck(:topic_id).compact
@container_class = "wrap not-found-container"
@top_viewed = TopicQuery.new(nil, except_topic_ids: category_topic_ids).list_top_for("monthly").topics.first(10)
@recent = Topic.where.not(id: category_topic_ids).recent(10)
@recent = Topic.includes(:category).where.not(id: category_topic_ids).recent(10)
@slug = params[:slug].class == String ? params[:slug] : ''
@slug = (params[:id].class == String ? params[:id] : '') if @slug.blank?
@slug.tr!('-', ' ')