PERF: n+1 query when fetching search_logs

This commit is contained in:
Arpit Jalan 2017-11-15 16:20:12 +05:30
parent 648832a643
commit 2e7c61681e

View File

@ -58,6 +58,7 @@ class SearchLog < ActiveRecord::Base
END) AS click_through,
MODE() WITHIN GROUP (ORDER BY clicked_topic_id) AS clicked_topic_id,
COUNT(DISTINCT ip_address) AS unique")
.includes(:topic)
.where('created_at > ?', start_of(period))
.group(:term)
.order('COUNT(DISTINCT ip_address) DESC')