Commit 77ad9a19 authored by jplang's avatar jplang

Speedup remove_inherited_roles (#22850).

Patch by Pavel Rosický.

git-svn-id: https://svn.redmine.org/redmine/trunk@15883 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e5b5f4bc
......@@ -72,9 +72,6 @@ class MemberRole < ActiveRecord::Base
end
def remove_inherited_roles
MemberRole.where(:inherited_from => id).group_by(&:member).
each do |member, member_roles|
member_roles.each(&:destroy)
end
MemberRole.where(:inherited_from => id).destroy_all
end
end
......@@ -844,7 +844,7 @@ class Project < ActiveRecord::Base
end
def remove_inherited_member_roles
member_roles = memberships.map(&:member_roles).flatten
member_roles = MemberRole.where(:member_id => membership_ids).to_a
member_role_ids = member_roles.map(&:id)
member_roles.each do |member_role|
if member_role.inherited_from && !member_role_ids.include?(member_role.inherited_from)
......
class AddIndexOnMemberRolesInheritedFrom < ActiveRecord::Migration
def change
add_index :member_roles, :inherited_from
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment