summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-06 14:03:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-06 14:03:49 +0000
commit8ee0b52d590d98a0cb56161135dfaf3a022ff2ee (patch)
tree33187a836b667abf01ad92f4921d51e4dcde177a /app
parent114537530f3a87bd3d988bf1b22bc59392040828 (diff)
downloadredmine-8ee0b52d590d98a0cb56161135dfaf3a022ff2ee.tar.gz
redmine-8ee0b52d590d98a0cb56161135dfaf3a022ff2ee.zip
Gantt perf: fixed that Project#start_date and #due_date run way too much queries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11135 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/issue.rb4
-rw-r--r--app/models/project.rb18
2 files changed, 14 insertions, 8 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 998030331..9a4b93bf5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -85,6 +85,10 @@ class Issue < ActiveRecord::Base
scope :on_active_project, lambda {
includes(:status, :project, :tracker).where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE)
}
+ scope :fixed_version, lambda {|versions|
+ ids = [versions].flatten.compact.map {|v| v.is_a?(Version) ? v.id : v}
+ ids.any? ? where(:fixed_version_id => ids) : where('1=0')
+ }
before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change
diff --git a/app/models/project.rb b/app/models/project.rb
index 13842b6e6..bdce62694 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -289,6 +289,8 @@ class Project < ActiveRecord::Base
@allowed_parents = nil
@allowed_permissions = nil
@actions_allowed = nil
+ @start_date = nil
+ @due_date = nil
super
end
@@ -538,20 +540,20 @@ class Project < ActiveRecord::Base
# The earliest start date of a project, based on it's issues and versions
def start_date
- [
+ @start_date ||= [
issues.minimum('start_date'),
- shared_versions.collect(&:effective_date),
- shared_versions.collect(&:start_date)
- ].flatten.compact.min
+ shared_versions.minimum('effective_date'),
+ Issue.fixed_version(shared_versions).minimum('start_date')
+ ].compact.min
end
# The latest due date of an issue or version
def due_date
- [
+ @due_date ||= [
issues.maximum('due_date'),
- shared_versions.collect(&:effective_date),
- shared_versions.collect {|v| v.fixed_issues.maximum('due_date')}
- ].flatten.compact.max
+ shared_versions.maximum('effective_date'),
+ Issue.fixed_version(shared_versions).maximum('due_date')
+ ].compact.max
end
def overdue?