diff options
author | Alexander Koval <al3xander.koval@gmail.com> | 2019-02-26 20:13:45 +0300 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2019-02-26 20:13:45 +0300 |
commit | 35c10922820e3e07a5c571e3ad81e90045b2da2b (patch) | |
tree | 45351a6a7960a0c8d156d51a7af46d29840ab5d1 /app | |
parent | 3a29b6af828da63ff7142183135d5ddbbd90d940 (diff) |
Reduce code duplication
Move logic of obtaining Issuable data to separate method
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/issuable.rb | 6 | ||||
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | app/views/shared/_issuable_meta_data.html.haml | 2 |
3 files changed, 8 insertions, 4 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 429a63f83cc..670103bc3f3 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -28,7 +28,7 @@ module Issuable # This object is used to gather issuable meta data for displaying # upvotes, downvotes, notes and closing merge requests count for issues and merge requests # lists avoiding n+1 queries and improving performance. - IssuableMeta = Struct.new(:upvotes, :downvotes, :notes_count, :merge_requests_count) + IssuableMeta = Struct.new(:upvotes, :downvotes, :user_notes_count, :merge_requests_count) included do cache_markdown_field :title, pipeline: :single_line @@ -36,8 +36,8 @@ module Issuable redact_field :description - belongs_to :author, class_name: "User" - belongs_to :updated_by, class_name: "User" + belongs_to :author, class_name: 'User' + belongs_to :updated_by, class_name: 'User' belongs_to :last_edited_by, class_name: 'User' belongs_to :milestone diff --git a/app/models/issue.rb b/app/models/issue.rb index 0b46e949052..071ad50fddc 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -263,6 +263,10 @@ class Issue < ActiveRecord::Base end # rubocop: enable CodeReuse/ServiceClass + def merge_requests_count + merge_requests_closing_issues.count + end + private def ensure_metrics diff --git a/app/views/shared/_issuable_meta_data.html.haml b/app/views/shared/_issuable_meta_data.html.haml index 6cc8c485666..31a5370a5f8 100644 --- a/app/views/shared/_issuable_meta_data.html.haml +++ b/app/views/shared/_issuable_meta_data.html.haml @@ -1,4 +1,4 @@ -- note_count = @issuable_meta_data[issuable.id].notes_count +- note_count = @issuable_meta_data[issuable.id].user_notes_count - issue_votes = @issuable_meta_data[issuable.id] - upvotes, downvotes = issue_votes.upvotes, issue_votes.downvotes - issuable_url = @collection_type == "Issue" ? issue_path(issuable, anchor: 'notes') : merge_request_path(issuable, anchor: 'notes') |