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:
parent
fe481453c4
commit
1c0988cad3
|
@ -123,17 +123,20 @@ class Version < ActiveRecord::Base
|
||||||
|
|
||||||
# Returns assigned issues count
|
# Returns assigned issues count
|
||||||
def issues_count
|
def issues_count
|
||||||
@issue_count ||= fixed_issues.count
|
load_issue_counts
|
||||||
|
@issue_count
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the total amount of open issues for this version.
|
# Returns the total amount of open issues for this version.
|
||||||
def open_issues_count
|
def open_issues_count
|
||||||
@open_issues_count ||= Issue.open.count(:all, :conditions => ["fixed_version_id = ?", self.id])
|
load_issue_counts
|
||||||
|
@open_issues_count
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the total amount of closed issues for this version.
|
# Returns the total amount of closed issues for this version.
|
||||||
def closed_issues_count
|
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
|
end
|
||||||
|
|
||||||
def wiki_page
|
def wiki_page
|
||||||
|
@ -194,6 +197,21 @@ class Version < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
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.
|
# Update the issue's fixed versions. Used if a version's sharing changes.
|
||||||
def update_issues_from_sharing_change
|
def update_issues_from_sharing_change
|
||||||
if sharing_changed?
|
if sharing_changed?
|
||||||
|
|
Loading…
Reference in New Issue