Use a single query to retrieve issues_count, open_issues_count and closed_issues_count.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9056 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-03-02 16:26:06 +00:00
parent fe481453c4
commit 1c0988cad3
1 changed files with 21 additions and 3 deletions

View File

@ -123,17 +123,20 @@ class Version < ActiveRecord::Base
# Returns assigned issues count
def issues_count
@issue_count ||= fixed_issues.count
load_issue_counts
@issue_count
end
# Returns the total amount of open issues for this version.
def open_issues_count
@open_issues_count ||= Issue.open.count(:all, :conditions => ["fixed_version_id = ?", self.id])
load_issue_counts
@open_issues_count
end
# Returns the total amount of closed issues for this version.
def closed_issues_count
@closed_issues_count ||= Issue.open(false).count(:all, :conditions => ["fixed_version_id = ?", self.id])
load_issue_counts
@closed_issues_count
end
def wiki_page
@ -194,6 +197,21 @@ class Version < ActiveRecord::Base
private
def load_issue_counts
unless @issue_count
@open_issues_count = 0
@closed_issues_count = 0
fixed_issues.count(:all, :group => :status).each do |status, count|
if status.is_closed?
@closed_issues_count += count
else
@open_issues_count += count
end
end
@issue_count = @open_issues_count + @closed_issues_count
end
end
# Update the issue's fixed versions. Used if a version's sharing changes.
def update_issues_from_sharing_change
if sharing_changed?