Optimize updates of issue's shared versions.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3137 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8f85ba79bc
commit
0fe389b841
app/models
@ -340,12 +340,31 @@ class Issue < ActiveRecord::Base
|
|||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update all issues so their versions are not pointing to a
|
# Unassigns issues from +version+ if it's no longer shared with issue's project
|
||||||
# fixed_version that is outside of the issue's project hierarchy.
|
def self.update_versions_from_sharing_change(version)
|
||||||
#
|
# Update issues assigned to the version
|
||||||
# OPTIMIZE: does a full table scan of Issues with a fixed_version.
|
update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
|
||||||
def self.update_fixed_versions_from_sharing_change(conditions=nil)
|
end
|
||||||
Issue.all(:conditions => merge_conditions('fixed_version_id IS NOT NULL', conditions),
|
|
||||||
|
# Unassigns issues from versions that are no longer shared
|
||||||
|
# after +project+ was moved
|
||||||
|
def self.update_versions_from_hierarchy_change(project)
|
||||||
|
moved_project_ids = project.self_and_descendants.reload.collect(&:id)
|
||||||
|
# Update issues of the moved projects and issues assigned to a version of a moved project
|
||||||
|
Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Update issues so their versions are not pointing to a
|
||||||
|
# fixed_version that is not shared with the issue's project
|
||||||
|
def self.update_versions(conditions=nil)
|
||||||
|
# Only need to update issues with a fixed_version from
|
||||||
|
# a different project and that is not systemwide shared
|
||||||
|
Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
|
||||||
|
" AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
|
||||||
|
" AND #{Version.table_name}.sharing <> 'system'",
|
||||||
|
conditions),
|
||||||
:include => [:project, :fixed_version]
|
:include => [:project, :fixed_version]
|
||||||
).each do |issue|
|
).each do |issue|
|
||||||
next if issue.project.nil? || issue.fixed_version.nil?
|
next if issue.project.nil? || issue.fixed_version.nil?
|
||||||
@ -357,8 +376,6 @@ class Issue < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# Callback on attachment deletion
|
# Callback on attachment deletion
|
||||||
def attachment_removed(obj)
|
def attachment_removed(obj)
|
||||||
journal = init_journal(User.current)
|
journal = init_journal(User.current)
|
||||||
|
@ -304,7 +304,7 @@ class Project < ActiveRecord::Base
|
|||||||
# move_to_child_of adds the project in last (ie.right) position
|
# move_to_child_of adds the project in last (ie.right) position
|
||||||
move_to_child_of(p)
|
move_to_child_of(p)
|
||||||
end
|
end
|
||||||
Issue.update_fixed_versions_from_sharing_change
|
Issue.update_versions_from_hierarchy_change(self)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
# Can not move to the given target
|
# Can not move to the given target
|
||||||
|
@ -166,7 +166,7 @@ private
|
|||||||
if VERSION_SHARINGS.index(sharing_was).nil? ||
|
if VERSION_SHARINGS.index(sharing_was).nil? ||
|
||||||
VERSION_SHARINGS.index(sharing).nil? ||
|
VERSION_SHARINGS.index(sharing).nil? ||
|
||||||
VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
|
VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
|
||||||
Issue.update_fixed_versions_from_sharing_change ["fixed_version_id = ? AND #{Issue.table_name}.project_id <> ?", id, project_id]
|
Issue.update_versions_from_sharing_change self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user