]> source.dussan.org Git - redmine.git/commitdiff
Optimize issue updates when a version sharing changes.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 8 Dec 2009 16:22:21 +0000 (16:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 8 Dec 2009 16:22:21 +0000 (16:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3135 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
app/models/project.rb
app/models/version.rb

index f75391f435e163854e376a3304dfb85a572dcb11..27029af13340f53ff60d334db123e43565916394 100644 (file)
@@ -344,8 +344,8 @@ class Issue < ActiveRecord::Base
   # fixed_version that is outside of the issue's project hierarchy.
   #
   # OPTIMIZE: does a full table scan of Issues with a fixed_version.
-  def self.update_fixed_versions_from_project_hierarchy_change
-    Issue.all(:conditions => ['fixed_version_id IS NOT NULL'],
+  def self.update_fixed_versions_from_sharing_change(conditions=nil)
+    Issue.all(:conditions => merge_conditions('fixed_version_id IS NOT NULL', conditions),
               :include => [:project, :fixed_version]
               ).each do |issue|
       next if issue.project.nil? || issue.fixed_version.nil?
index 593e60c9e078c20e560498c3d8acd97014057fb6..9e2f4830da28f027fdef24e708e2b0c1754b5d4c 100644 (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(p)
       end
-      Issue.update_fixed_versions_from_project_hierarchy_change
+      Issue.update_fixed_versions_from_sharing_change
       true
     else
       # Can not move to the given target
index add0dc734cc912fbc4da8daecabc1ed9b3f1d082..fa9eb28e72937e182d17a3a583d3346bf4d05640 100644 (file)
@@ -17,7 +17,7 @@
 
 class Version < ActiveRecord::Base
   before_destroy :check_integrity
-  after_update :update_issue_versions
+  after_update :update_issues_from_sharing_change
   belongs_to :project
   has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
   acts_as_customizable
@@ -161,9 +161,13 @@ private
   end
 
   # 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?
-      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