Commit a3f64b19 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve performance for merge_request#show page

* store @participants in variable
* store result of subscribed? call into variable

In total it reduce amount of SQL queries for merge_request with 10
comments/participants twice.
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a5f23435
...@@ -246,6 +246,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -246,6 +246,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def define_show_vars def define_show_vars
@participants = @merge_request.participants(current_user, @project)
# Build a note object for comment form # Build a note object for comment form
@note = @project.notes.new(noteable: @merge_request) @note = @project.notes.new(noteable: @merge_request)
@notes = @merge_request.mr_and_commit_notes.inc_author.fresh @notes = @merge_request.mr_and_commit_notes.inc_author.fresh
......
...@@ -30,18 +30,19 @@ ...@@ -30,18 +30,19 @@
= f.submit class: 'btn' = f.submit class: 'btn'
- if current_user - if current_user
- subscribed = @merge_request.subscribed?(current_user)
%div.prepend-top-20.clearfix %div.prepend-top-20.clearfix
.issuable-context-title .issuable-context-title
%label %label
Subscription: Subscription:
%button.btn.btn-block.subscribe-button{:type => 'button'} %button.btn.btn-block.subscribe-button{:type => 'button'}
= icon('eye') = icon('eye')
%span= @merge_request.subscribed?(current_user) ? 'Unsubscribe' : 'Subscribe' %span= subscribed ? 'Unsubscribe' : 'Subscribe'
- subscribtion_status = @merge_request.subscribed?(current_user) ? 'subscribed' : 'unsubscribed' - subscribtion_status = subscribed ? 'subscribed' : 'unsubscribed'
.subscription-status{data: {status: subscribtion_status}} .subscription-status{data: {status: subscribtion_status}}
.description-block.unsubscribed{class: ( 'hidden' if @merge_request.subscribed?(current_user) )} .description-block.unsubscribed{class: ( 'hidden' if subscribed )}
You're not receiving notifications from this thread. You're not receiving notifications from this thread.
.description-block.subscribed{class: ( 'hidden' unless @merge_request.subscribed?(current_user) )} .description-block.subscribed{class: ( 'hidden' unless subscribed )}
You're receiving notifications because you're subscribed to this thread. You're receiving notifications because you're subscribed to this thread.
:coffeescript :coffeescript
......
.participants .participants
%span #{@merge_request.participants(current_user).count} participants %span #{@participants.count} participants
- @merge_request.participants(current_user).each do |participant| - @participants.each do |participant|
= link_to_member(@project, participant, name: false, size: 24) = link_to_member(@project, participant, name: false, size: 24)
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