diff options
author | Go MAEDA <maeda@farend.jp> | 2023-10-09 05:19:28 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2023-10-09 05:19:28 +0000 |
commit | ad3e2bdd1b1b141b507bf708bb569973d090d7b9 (patch) | |
tree | e4bec8c8264ac870e96c90090b9c9b74e87df8fa /app/models/issue_query.rb | |
parent | 43873746bae72f620d4813977447ea59db37fbe5 (diff) | |
download | redmine-ad3e2bdd1b1b141b507bf708bb569973d090d7b9.tar.gz redmine-ad3e2bdd1b1b141b507bf708bb569973d090d7b9.zip |
Refactor SQL construction in IssueQuery#sql_for_assigned_to_role_field for better readability (#38319).
git-svn-id: https://svn.redmine.org/redmine/trunk@22333 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_query.rb')
-rw-r--r-- | app/models/issue_query.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 410f053f5..672785cc1 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -566,8 +566,11 @@ class IssueQuery < Query when "*", "!*" # Member / Not member sw = operator == "!*" ? 'NOT' : '' nl = operator == "!*" ? "#{Issue.table_name}.assigned_to_id IS NULL OR" : '' - "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (SELECT DISTINCT #{Member.table_name}.user_id FROM #{Member.table_name}" + - " WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id))" + subquery = + "SELECT DISTINCT #{Member.table_name}.user_id" + + " FROM #{Member.table_name}" + + " WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id" + "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (#{subquery}))" when "=", "!" role_cond = if value.any? @@ -577,8 +580,11 @@ class IssueQuery < Query end sw = operator == "!" ? 'NOT' : '' nl = operator == "!" ? "#{Issue.table_name}.assigned_to_id IS NULL OR" : '' - "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (SELECT DISTINCT #{Member.table_name}.user_id FROM #{Member.table_name}, #{MemberRole.table_name}" + - " WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id AND #{Member.table_name}.id = #{MemberRole.table_name}.member_id AND #{role_cond}))" + subquery = + "SELECT DISTINCT #{Member.table_name}.user_id" + + " FROM #{Member.table_name}, #{MemberRole.table_name}" + + " WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id AND #{Member.table_name}.id = #{MemberRole.table_name}.member_id AND #{role_cond}" + "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (#{subquery}))" end end |