From a3f64b195effa4ac5fca657df3e74696158416b1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 24 Jun 2015 12:56:10 +0200 Subject: 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 --- app/controllers/projects/merge_requests_controller.rb | 2 ++ app/views/projects/merge_requests/show/_context.html.haml | 9 +++++---- app/views/projects/merge_requests/show/_participants.html.haml | 4 ++-- 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) -- cgit v1.2.1