Commit b11492c2 authored by Adam Niedzielski's avatar Adam Niedzielski

Use cached values to compute total issues count in milestone index pages

Milestoneish#issues_visible_to_user caches only the ActiveRecord relation,
not the actual result.
Introduce Milestoneish#total_issues_count that relies on the cached method
Milestoneish#count_issues_by_state to reduce the number of queries.
parent bb02141e
...@@ -7,11 +7,14 @@ module Milestoneish ...@@ -7,11 +7,14 @@ module Milestoneish
def total_items_count(user) def total_items_count(user)
memoize_per_user(user, :total_items_count) do memoize_per_user(user, :total_items_count) do
issues_count = count_issues_by_state(user).values.sum total_issues_count(user) + merge_requests.size
issues_count + merge_requests.size
end end
end end
def total_issues_count(user)
count_issues_by_state(user).values.sum
end
def complete?(user) def complete?(user)
total_items_count(user) > 0 && total_items_count(user) == closed_items_count(user) total_items_count(user) > 0 && total_items_count(user) == closed_items_count(user)
end end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
.pull-right.light #{milestone.percent_complete(current_user)}% complete .pull-right.light #{milestone.percent_complete(current_user)}% complete
.row .row
.col-sm-6 .col-sm-6
= link_to pluralize(milestone.issues_visible_to_user(current_user).size, 'Issue'), issues_path = link_to pluralize(milestone.total_issues_count(current_user), 'Issue'), issues_path
· ·
= link_to pluralize(milestone.merge_requests.size, 'Merge Request'), merge_requests_path = link_to pluralize(milestone.merge_requests.size, 'Merge Request'), merge_requests_path
.col-sm-6= milestone_progress_bar(milestone) .col-sm-6= milestone_progress_bar(milestone)
......
---
title: Use cached values to compute total issues count in milestone index pages
merge_request: 8518
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment