Optimize issue updates when a version sharing changes.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3135 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-12-08 16:22:21 +00:00
parent 517a87f8c5
commit 40e2af7ab9
3 changed files with 10 additions and 6 deletions

View File

@ -344,8 +344,8 @@ class Issue < ActiveRecord::Base
# fixed_version that is outside of the issue's project hierarchy. # fixed_version that is outside of the issue's project hierarchy.
# #
# OPTIMIZE: does a full table scan of Issues with a fixed_version. # OPTIMIZE: does a full table scan of Issues with a fixed_version.
def self.update_fixed_versions_from_project_hierarchy_change def self.update_fixed_versions_from_sharing_change(conditions=nil)
Issue.all(:conditions => ['fixed_version_id IS NOT NULL'], Issue.all(:conditions => merge_conditions('fixed_version_id IS NOT NULL', 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?

View File

@ -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_project_hierarchy_change Issue.update_fixed_versions_from_sharing_change
true true
else else
# Can not move to the given target # Can not move to the given target

View File

@ -17,7 +17,7 @@
class Version < ActiveRecord::Base class Version < ActiveRecord::Base
before_destroy :check_integrity before_destroy :check_integrity
after_update :update_issue_versions after_update :update_issues_from_sharing_change
belongs_to :project belongs_to :project
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id' has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
acts_as_customizable acts_as_customizable
@ -161,9 +161,13 @@ private
end end
# Update the issue's fixed versions. Used if a version's sharing changes. # Update the issue's fixed versions. Used if a version's sharing changes.
def update_issue_versions def update_issues_from_sharing_change
if sharing_changed? if sharing_changed?
Issue.update_fixed_versions_from_project_hierarchy_change if VERSION_SHARINGS.index(sharing_was).nil? ||
VERSION_SHARINGS.index(sharing).nil? ||
VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
Issue.update_fixed_versions_from_sharing_change ['fixed_version_id = ?', id]
end
end end
end end