From 3e099ab2b1e76689a0aadc1797c841bfcd40f146 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 5 Dec 2016 17:37:43 +1100 Subject: [PATCH] PERF: avoid query on every logged on page load --- app/models/user_option.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/user_option.rb b/app/models/user_option.rb index 99be107d215..7ef3b5262af 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -87,8 +87,14 @@ class UserOption < ActiveRecord::Base def redirected_to_top # redirect is enabled return unless SiteSetting.redirect_users_to_top_page + + # PERF: bypass min_redirected_to_top query for users that were seen already + return if user.trust_level > 0 && user.last_seen_at && user.last_seen_at > 1.month.ago + # top must be in the top_menu return unless SiteSetting.top_menu =~ /(^|\|)top(\||$)/i + + # not enough topics return unless period = SiteSetting.min_redirected_to_top_period(1.days.ago)