From: Go MAEDA Date: Sun, 23 Jan 2022 11:55:44 +0000 (+0000) Subject: Reduce extra database queries in IssueQuery.default (#7360, #36503). X-Git-Tag: 5.0.0~88 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=146097c6108813520fca703cf072914c8f032c00;p=redmine.git Reduce extra database queries in IssueQuery.default (#7360, #36503). git-svn-id: http://svn.redmine.org/redmine/trunk@21387 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index e09a808d3..5a3e14474 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -79,11 +79,17 @@ class IssueQuery < Query def self.default(project: nil, user: User.current) query = nil - if user&.logged? - query = find_by_id user.pref.default_issue_query + # user default + if user&.logged? && (query_id = user.pref.default_issue_query) + query = find_by(id: query_id) end + # project default query ||= project&.default_issue_query - query || find_by_id(Setting.default_issue_query) + # global default + if query.nil? && (query_id = Setting.default_issue_query).present? + query = find_by(id: query_id) + end + query end def initialize(attributes=nil, *args)