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.