summaryrefslogtreecommitdiffstats
path: root/app/models/custom_field.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-05 14:23:36 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-05 14:23:36 +0000
commit77ac3b7891d40196b04f41af4da357a95b90d149 (patch)
tree227e89a7db79e443cd111283ae41a07c4f560817 /app/models/custom_field.rb
parent7087dbb5b426f04c01482adebac40ca87e4af591 (diff)
downloadredmine-77ac3b7891d40196b04f41af4da357a95b90d149.tar.gz
redmine-77ac3b7891d40196b04f41af4da357a95b90d149.zip
Reduces the number of subqueries when searching with many custom fields set as searchable (#15781).
git-svn-id: http://svn.redmine.org/redmine/trunk@12481 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/custom_field.rb')
-rw-r--r--app/models/custom_field.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index b2c54d030..72ac471fd 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -173,17 +173,18 @@ class CustomField < ActiveRecord::Base
format.join_for_order_statement(self)
end
- def visibility_by_project_condition(project_key=nil, user=User.current)
+ def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil)
if visible? || user.admin?
"1=1"
elsif user.anonymous?
"1=0"
else
project_key ||= "#{self.class.customized_class.table_name}.project_id"
+ id_column ||= id
"#{project_key} IN (SELECT DISTINCT m.project_id FROM #{Member.table_name} m" +
" INNER JOIN #{MemberRole.table_name} mr ON mr.member_id = m.id" +
" INNER JOIN #{table_name_prefix}custom_fields_roles#{table_name_suffix} cfr ON cfr.role_id = mr.role_id" +
- " WHERE m.user_id = #{user.id} AND cfr.custom_field_id = #{id})"
+ " WHERE m.user_id = #{user.id} AND cfr.custom_field_id = #{id_column})"
end
end