summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-24 12:56:10 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-24 12:56:10 +0200
commita3f64b195effa4ac5fca657df3e74696158416b1 (patch)
tree6a0e0dc1c49b8beff26d0967b17fe42b356c8788
parenta5f23435f7d8b8040ed6b80322ccea3fa8323468 (diff)
downloadgitlab-ce-a3f64b195effa4ac5fca657df3e74696158416b1.tar.gz
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: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/projects/merge_requests_controller.rb2
-rw-r--r--app/views/projects/merge_requests/show/_context.html.haml9
-rw-r--r--app/views/projects/merge_requests/show/_participants.html.haml4
3 files changed, 9 insertions, 6 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 51ecbfd561a..a13688305b7 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -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
diff --git a/app/views/projects/merge_requests/show/_context.html.haml b/app/views/projects/merge_requests/show/_context.html.haml
index 1d0e2e350b0..5f2f65e0087 100644
--- a/app/views/projects/merge_requests/show/_context.html.haml
+++ b/app/views/projects/merge_requests/show/_context.html.haml
@@ -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
diff --git a/app/views/projects/merge_requests/show/_participants.html.haml b/app/views/projects/merge_requests/show/_participants.html.haml
index 9c93fa55fe6..c67afe963e7 100644
--- a/app/views/projects/merge_requests/show/_participants.html.haml
+++ b/app/views/projects/merge_requests/show/_participants.html.haml
@@ -1,4 +1,4 @@
.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)