]> source.dussan.org Git - redmine.git/commitdiff
Reduce extra queries in @ProjectQuery.default@ (#37135).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sat, 28 May 2022 09:54:34 +0000 (09:54 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sat, 28 May 2022 09:54:34 +0000 (09:54 +0000)
Patch by Dmitry Makurin.

git-svn-id: https://svn.redmine.org/redmine/trunk@21614 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project_query.rb

index 852beb95c9e51edc250efe7888108c06873d16b1..57d0330d123e597a976937285cbb51f89c86360c 100644 (file)
@@ -41,10 +41,13 @@ class ProjectQuery < Query
 
   def self.default(project: nil, user: User.current)
     query = nil
-    if user&.logged?
-      query = find_by_id user.pref.default_project_query
+    if user&.logged? && (query_id = user.pref.default_project_query).present?
+      query = find_by(id: query_id)
     end
-    query || find_by_id(Setting.default_project_query)
+    if query.nil? && (query_id = Setting.default_project_query).present?
+      query = find_by(id: query_id)
+    end
+    query
   end
 
   def initialize(attributes=nil, *args)