2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

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, END) AS click_through,
MODE() WITHIN GROUP (ORDER BY clicked_topic_id) AS clicked_topic_id, MODE() WITHIN GROUP (ORDER BY clicked_topic_id) AS clicked_topic_id,
COUNT(DISTINCT ip_address) AS unique") COUNT(DISTINCT ip_address) AS unique")
.includes(:topic)
.where('created_at > ?', start_of(period)) .where('created_at > ?', start_of(period))
.group(:term) .group(:term)
.order('COUNT(DISTINCT ip_address) DESC') .order('COUNT(DISTINCT ip_address) DESC')