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
end
def define_show_vars
@participants = @merge_request.participants(current_user, @project)
# Build a note object for comment form
@note = @project.notes.new(noteable: @merge_request)
@notes = @merge_request.mr_and_commit_notes.inc_author.fresh
......
......@@ -30,18 +30,19 @@
= f.submit class: 'btn'
- if current_user
- subscribed = @merge_request.subscribed?(current_user)
%div.prepend-top-20.clearfix
.issuable-context-title
%label
Subscription:
%button.btn.btn-block.subscribe-button{:type => 'button'}
= icon('eye')
%span= @merge_request.subscribed?(current_user) ? 'Unsubscribe' : 'Subscribe'
- subscribtion_status = @merge_request.subscribed?(current_user) ? 'subscribed' : 'unsubscribed'
%span= subscribed ? 'Unsubscribe' : 'Subscribe'
- subscribtion_status = subscribed ? 'subscribed' : 'unsubscribed'
.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.
.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.
:coffeescript
......
.participants
%span #{@merge_request.participants(current_user).count} participants
- @merge_request.participants(current_user).each do |participant|
%span #{@participants.count} participants
- @participants.each do |participant|
= 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