##// END OF EJS Templates
Optimize updates of issue's shared versions....
Jean-Philippe Lang -
r3023:0fe389b8417f
parent child
Show More
@@ -340,12 +340,31 class Issue < ActiveRecord::Base
340 340 s
341 341 end
342 342
343 # Update all issues so their versions are not pointing to a
344 # fixed_version that is outside of the issue's project hierarchy.
345 #
346 # OPTIMIZE: does a full table scan of Issues with a fixed_version.
347 def self.update_fixed_versions_from_sharing_change(conditions=nil)
348 Issue.all(:conditions => merge_conditions('fixed_version_id IS NOT NULL', conditions),
343 # Unassigns issues from +version+ if it's no longer shared with issue's project
344 def self.update_versions_from_sharing_change(version)
345 # Update issues assigned to the version
346 update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
347 end
348
349 # Unassigns issues from versions that are no longer shared
350 # after +project+ was moved
351 def self.update_versions_from_hierarchy_change(project)
352 moved_project_ids = project.self_and_descendants.reload.collect(&:id)
353 # Update issues of the moved projects and issues assigned to a version of a moved project
354 Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
355 end
356
357 private
358
359 # Update issues so their versions are not pointing to a
360 # fixed_version that is not shared with the issue's project
361 def self.update_versions(conditions=nil)
362 # Only need to update issues with a fixed_version from
363 # a different project and that is not systemwide shared
364 Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
365 " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
366 " AND #{Version.table_name}.sharing <> 'system'",
367 conditions),
349 368 :include => [:project, :fixed_version]
350 369 ).each do |issue|
351 370 next if issue.project.nil? || issue.fixed_version.nil?
@@ -357,8 +376,6 class Issue < ActiveRecord::Base
357 376 end
358 377 end
359 378
360 private
361
362 379 # Callback on attachment deletion
363 380 def attachment_removed(obj)
364 381 journal = init_journal(User.current)
@@ -304,7 +304,7 class Project < ActiveRecord::Base
304 304 # move_to_child_of adds the project in last (ie.right) position
305 305 move_to_child_of(p)
306 306 end
307 Issue.update_fixed_versions_from_sharing_change
307 Issue.update_versions_from_hierarchy_change(self)
308 308 true
309 309 else
310 310 # Can not move to the given target
@@ -166,7 +166,7 private
166 166 if VERSION_SHARINGS.index(sharing_was).nil? ||
167 167 VERSION_SHARINGS.index(sharing).nil? ||
168 168 VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
169 Issue.update_fixed_versions_from_sharing_change ["fixed_version_id = ? AND #{Issue.table_name}.project_id <> ?", id, project_id]
169 Issue.update_versions_from_sharing_change self
170 170 end
171 171 end
172 172 end
General Comments 0
You need to be logged in to leave comments. Login now