Index: app/models/issue.rb =================================================================== --- app/models/issue.rb (revision 14670) +++ app/models/issue.rb (working copy) @@ -208,6 +208,7 @@ @spent_hours = nil @total_spent_hours = nil @total_estimated_hours = nil + @attachment_count = nil base_reload(*args) end @@ -1007,6 +1008,16 @@ end end + def self.load_attachment_counts(issues) + if issues.any? + issue_ids = issues.map(&:id) + attachment_counts = Attachment.where(:container_type => 'Issue', :container_id => issue_ids).group(:container_id).count + issues.each do |issue| + issue.instance_variable_set("@attachment_count", attachment_counts[issue.id] || 0) + end + end + end + # Finds an issue relation given its id. def find_relation(relation_id) IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id) @@ -1389,6 +1400,10 @@ Project.where(condition).having_trackers end + def attachment_count + @attachment_count ||= attachments.count + end + private def after_project_change Index: app/models/issue_query.rb =================================================================== --- app/models/issue_query.rb (revision 14675) +++ app/models/issue_query.rb (working copy) @@ -359,6 +359,7 @@ end issues = scope.to_a + Issue.load_attachment_counts(issues) if has_column?(:spent_hours) Issue.load_visible_spent_hours(issues) Index: app/views/issues/_list.html.erb =================================================================== --- app/views/issues/_list.html.erb (revision 14665) +++ app/views/issues/_list.html.erb (working copy) @@ -27,7 +27,7 @@ <% end %> -