Commit 0c8b96bd authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'performance-improvements' into 'master'

Performance improvements

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

In total it reduce amount of SQL queries for issue or merge_request with 10 comments/participants almost twice.

See merge request !883
parents d2de219f 82f372c7
...@@ -19,6 +19,7 @@ v 7.13.0 (unreleased) ...@@ -19,6 +19,7 @@ v 7.13.0 (unreleased)
- Allow Administrators to filter the user list by those with or without Two-factor Authentication enabled. - Allow Administrators to filter the user list by those with or without Two-factor Authentication enabled.
- Show a user's Two-factor Authentication status in the administration area. - Show a user's Two-factor Authentication status in the administration area.
- Explicit error when commit not found in the CI - Explicit error when commit not found in the CI
- Improve performance for issue and merge request pages
v 7.12.0 (unreleased) v 7.12.0 (unreleased)
- Fix Error 500 when one user attempts to access a personal, internal snippet (Stan Hu) - Fix Error 500 when one user attempts to access a personal, internal snippet (Stan Hu)
......
...@@ -364,3 +364,12 @@ table { ...@@ -364,3 +364,12 @@ table {
margin-top: 8px; margin-top: 8px;
} }
} }
.profiler-results {
top: 50px !important;
.profiler-button,
.profiler-controls {
border-color: #EEE !important;
}
}
...@@ -55,6 +55,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -55,6 +55,7 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def show def show
@participants = @issue.participants(current_user, @project)
@note = @project.notes.new(noteable: @issue) @note = @project.notes.new(noteable: @issue)
@notes = @issue.notes.inc_author.fresh @notes = @issue.notes.inc_author.fresh
@noteable = @issue @noteable = @issue
......
...@@ -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
......
...@@ -35,6 +35,8 @@ module Participable ...@@ -35,6 +35,8 @@ module Participable
end end
end end
# Be aware that this method makes a lot of sql queries.
# Save result into variable if you are going to reuse it inside same request
def participants(current_user = self.author, project = self.project) def participants(current_user = self.author, project = self.project)
participants = self.class.participant_attrs.flat_map do |attr| participants = self.class.participant_attrs.flat_map do |attr|
meth = method(attr) meth = method(attr)
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
.votes-holder.pull-right .votes-holder.pull-right
#votes= render 'votes/votes_block', votable: @issue #votes= render 'votes/votes_block', votable: @issue
.participants .participants
%span= pluralize(@issue.participants(current_user).count, 'participant') %span= pluralize(@participants.count, 'participant')
- @issue.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)
.voting_notes#notes= render 'projects/notes/notes_with_form' .voting_notes#notes= render 'projects/notes/notes_with_form'
%aside.col-md-3 %aside.col-md-3
......
...@@ -28,18 +28,19 @@ ...@@ -28,18 +28,19 @@
= f.submit class: 'btn' = f.submit class: 'btn'
- if current_user - if current_user
- subscribed = @issue.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'}
%i.fa.fa-eye %i.fa.fa-eye
%span= @issue.subscribed?(current_user) ? "Unsubscribe" : "Subscribe" %span= subscribed ? "Unsubscribe" : "Subscribe"
- subscribtion_status = @issue.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 @issue.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 @issue.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
......
...@@ -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)
...@@ -5,6 +5,6 @@ if Rails.env.development? ...@@ -5,6 +5,6 @@ if Rails.env.development?
Rack::MiniProfilerRails.initialize!(Rails.application) Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.position = 'right' Rack::MiniProfiler.config.position = 'right'
Rack::MiniProfiler.config.start_hidden = true Rack::MiniProfiler.config.start_hidden = false
Rack::MiniProfiler.config.skip_paths << '/teaspoon' Rack::MiniProfiler.config.skip_paths << '/teaspoon'
end end
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