##// END OF EJS Templates
Gantt perf: fixed that Project#start_date and #due_date run way too much queries....
Jean-Philippe Lang -
r10905:8ee0b52d590d
parent child
Show More
@@ -85,6 +85,10 class Issue < ActiveRecord::Base
85 scope :on_active_project, lambda {
85 scope :on_active_project, lambda {
86 includes(:status, :project, :tracker).where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE)
86 includes(:status, :project, :tracker).where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE)
87 }
87 }
88 scope :fixed_version, lambda {|versions|
89 ids = [versions].flatten.compact.map {|v| v.is_a?(Version) ? v.id : v}
90 ids.any? ? where(:fixed_version_id => ids) : where('1=0')
91 }
88
92
89 before_create :default_assign
93 before_create :default_assign
90 before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change
94 before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change
@@ -289,6 +289,8 class Project < ActiveRecord::Base
289 @allowed_parents = nil
289 @allowed_parents = nil
290 @allowed_permissions = nil
290 @allowed_permissions = nil
291 @actions_allowed = nil
291 @actions_allowed = nil
292 @start_date = nil
293 @due_date = nil
292 super
294 super
293 end
295 end
294
296
@@ -538,20 +540,20 class Project < ActiveRecord::Base
538
540
539 # The earliest start date of a project, based on it's issues and versions
541 # The earliest start date of a project, based on it's issues and versions
540 def start_date
542 def start_date
541 [
543 @start_date ||= [
542 issues.minimum('start_date'),
544 issues.minimum('start_date'),
543 shared_versions.collect(&:effective_date),
545 shared_versions.minimum('effective_date'),
544 shared_versions.collect(&:start_date)
546 Issue.fixed_version(shared_versions).minimum('start_date')
545 ].flatten.compact.min
547 ].compact.min
546 end
548 end
547
549
548 # The latest due date of an issue or version
550 # The latest due date of an issue or version
549 def due_date
551 def due_date
550 [
552 @due_date ||= [
551 issues.maximum('due_date'),
553 issues.maximum('due_date'),
552 shared_versions.collect(&:effective_date),
554 shared_versions.maximum('effective_date'),
553 shared_versions.collect {|v| v.fixed_issues.maximum('due_date')}
555 Issue.fixed_version(shared_versions).maximum('due_date')
554 ].flatten.compact.max
556 ].compact.max
555 end
557 end
556
558
557 def overdue?
559 def overdue?
@@ -309,6 +309,16 class IssueTest < ActiveSupport::TestCase
309 assert_equal issues, issues.select(&:closed?)
309 assert_equal issues, issues.select(&:closed?)
310 end
310 end
311
311
312 def test_fixed_version_scope_with_a_version_should_return_its_fixed_issues
313 version = Version.find(2)
314 assert version.fixed_issues.any?
315 assert_equal version.fixed_issues.to_a.sort, Issue.fixed_version(version).to_a.sort
316 end
317
318 def test_fixed_version_scope_with_empty_array_should_return_no_result
319 assert_equal 0, Issue.fixed_version([]).count
320 end
321
312 def test_errors_full_messages_should_include_custom_fields_errors
322 def test_errors_full_messages_should_include_custom_fields_errors
313 field = IssueCustomField.find_by_name('Database')
323 field = IssueCustomField.find_by_name('Database')
314
324
General Comments 0
You need to be logged in to leave comments. Login now