Patch #37135

Reduce extra queries in ProjectQuery.default

Added by Dmitry Makurin about 1 month ago. Updated 28 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Marius BALTEANU% Done:

0%

Category:Performance
Target version:5.0.2

Description

Same as #36503 but for ProjectQuery.
Currently redmine tries to select default_project_query even if settings are empty.

diff --git a/app/models/project_query.rb b/app/models/project_query.rb
index 002437aeb..8c6643c7b 100644
--- a/app/models/project_query.rb
+++ b/app/models/project_query.rb
@@ -39,10 +39,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)



Related issues

Related to Redmine - Feature #35795: Settings for global and user default custom ProjectQuery Closed
Copied from Redmine - Patch #36503: Reduce extra queries in IssueQuery.default Closed

Associated revisions

Revision 21614
Added by Marius BALTEANU 29 days ago

Reduce extra queries in ProjectQuery.default (#37135).

Patch by Dmitry Makurin.

Revision 21622
Added by Marius BALTEANU 28 days ago

Merged r21614 to 5.0-stable (#37135).

History

#1 Updated by Dmitry Makurin about 1 month ago

  • Copied from Patch #36503: Reduce extra queries in IssueQuery.default added

#2 Updated by Go MAEDA about 1 month ago

  • Description updated (diff)

#3 Updated by Go MAEDA about 1 month ago

  • Assignee deleted (Go MAEDA)
  • Target version set to 5.0.2

Setting the target version to 5.0.2.

#4 Updated by Go MAEDA about 1 month ago

  • Related to Feature #35795: Settings for global and user default custom ProjectQuery added

#5 Updated by Marius BALTEANU 29 days ago

  • Status changed from New to Resolved
  • Assignee set to Marius BALTEANU

Patch committed, thanks!

#6 Updated by Marius BALTEANU 28 days ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF