Commit 57c87b1e authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Backport gitlab-ce!11518 MR widget perf improvement

parent 1188042d
...@@ -176,7 +176,6 @@ export default { ...@@ -176,7 +176,6 @@ export default {
}); });
}, },
handleMounted() { handleMounted() {
this.checkStatus();
this.setFavicon(); this.setFavicon();
this.initDeploymentsPolling(); this.initDeploymentsPolling();
}, },
......
...@@ -6,7 +6,7 @@ Vue.use(VueResource); ...@@ -6,7 +6,7 @@ Vue.use(VueResource);
export default class MRWidgetService { export default class MRWidgetService {
constructor(endpoints) { constructor(endpoints) {
this.mergeResource = Vue.resource(endpoints.mergePath); this.mergeResource = Vue.resource(endpoints.mergePath);
this.mergeCheckResource = Vue.resource(endpoints.mergeCheckPath); this.mergeCheckResource = Vue.resource(endpoints.statusPath);
this.cancelAutoMergeResource = Vue.resource(endpoints.cancelAutoMergePath); this.cancelAutoMergeResource = Vue.resource(endpoints.cancelAutoMergePath);
this.removeWIPResource = Vue.resource(endpoints.removeWIPPath); this.removeWIPResource = Vue.resource(endpoints.removeWIPPath);
this.removeSourceBranchResource = Vue.resource(endpoints.sourceBranchPath); this.removeSourceBranchResource = Vue.resource(endpoints.sourceBranchPath);
......
...@@ -9,17 +9,18 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -9,17 +9,18 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled before_action :module_enabled
before_action :merge_request, only: [ before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :conflicts, :conflict_for_path, :pipelines, :merge, :merge_check, :edit, :update, :show, :diffs, :commits, :conflicts, :conflict_for_path, :pipelines, :merge,
:pipeline_status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds, :pipeline_status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds,
:remove_wip, :resolve_conflicts, :assign_related_issues, :commit_change_content, :remove_wip, :resolve_conflicts, :assign_related_issues, :commit_change_content,
# EE # EE
:approve, :approvals, :unapprove, :rebase :approve, :approvals, :unapprove, :rebase
] ]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :pipelines] before_action :validates_merge_request, only: [:show, :diffs, :commits, :pipelines]
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines] before_action :define_show_vars, only: [:diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines]
before_action :define_commit_vars, only: [:diffs] before_action :define_commit_vars, only: [:diffs]
before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds, :conflicts, :conflict_for_path, :pipelines] before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds, :conflicts, :conflict_for_path, :pipelines]
before_action :close_merge_request_without_source_project, only: [:show, :diffs, :commits, :builds, :pipelines] before_action :close_merge_request_without_source_project, only: [:show, :diffs, :commits, :builds, :pipelines]
before_action :check_if_can_be_merged, only: :show
before_action :apply_diff_view_cookie!, only: [:new_diffs] before_action :apply_diff_view_cookie!, only: [:new_diffs]
before_action :build_merge_request, only: [:new, :new_diffs] before_action :build_merge_request, only: [:new, :new_diffs]
before_action :set_suggested_approvers, only: [:new, :new_diffs, :edit] before_action :set_suggested_approvers, only: [:new, :new_diffs, :edit]
...@@ -79,9 +80,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -79,9 +80,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
define_discussion_vars define_discussion_vars
define_show_vars
end end
format.json do format.json do
Gitlab::PollingInterval.set_header(response, interval: 10_000)
render json: serializer.represent(@merge_request, basic: params[:basic]) render json: serializer.represent(@merge_request, basic: params[:basic])
end end
...@@ -319,12 +323,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -319,12 +323,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: serializer.represent(@merge_request) render json: serializer.represent(@merge_request)
end end
def merge_check
@merge_request.check_if_can_be_merged
render json: serializer.represent(@merge_request)
end
def commit_change_content def commit_change_content
render partial: 'projects/merge_requests/widget/commit_change_content', layout: false render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
end end
...@@ -727,6 +725,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -727,6 +725,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
private private
def check_if_can_be_merged
@merge_request.check_if_can_be_merged
end
def merge! def merge!
# Disable the CI check if merge_when_pipeline_succeeds is enabled since we have # Disable the CI check if merge_when_pipeline_succeeds is enabled since we have
# to wait until CI completes to know # to wait until CI completes to know
......
class MergeRequestBasicEntity < Grape::Entity class MergeRequestBasicEntity < Grape::Entity
expose :assignee_id
expose :merge_status expose :merge_status
expose :merge_error expose :merge_error
expose :state expose :state
......
class MergeRequestEntity < IssuableEntity class MergeRequestEntity < IssuableEntity
expose :assignee_id
include RequestAwareEntity include RequestAwareEntity
expose :in_progress_merge_commit_sha expose :in_progress_merge_commit_sha
...@@ -166,12 +165,6 @@ class MergeRequestEntity < IssuableEntity ...@@ -166,12 +165,6 @@ class MergeRequestEntity < IssuableEntity
format: :json) format: :json)
end end
expose :merge_check_path do |merge_request|
merge_check_namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project,
merge_request)
end
expose :ci_environments_status_path do |merge_request| expose :ci_environments_status_path do |merge_request|
ci_environments_status_namespace_project_merge_request_path(merge_request.project.namespace, ci_environments_status_namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project, merge_request.project,
......
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
:javascript :javascript
gl.sidebarOptions = { gl.sidebarOptions = {
endpoint: "#{issuable_json_path(issuable)}", endpoint: "#{issuable_json_path(issuable)}?basic=true",
editable: #{can_edit_issuable ? true : false}, editable: #{can_edit_issuable ? true : false},
currentUser: #{current_user.to_json(only: [:username, :id, :name], methods: :avatar_url)}, currentUser: #{current_user.to_json(only: [:username, :id, :name], methods: :avatar_url)},
rootPath: "#{root_path}" rootPath: "#{root_path}"
......
...@@ -74,7 +74,6 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -74,7 +74,6 @@ constraints(ProjectUrlConstrainer.new) do
get :conflicts get :conflicts
get :conflict_for_path get :conflict_for_path
get :pipelines get :pipelines
get :merge_check
get :commit_change_content get :commit_change_content
post :merge post :merge
post :cancel_merge_when_pipeline_succeeds post :cancel_merge_when_pipeline_succeeds
......
...@@ -282,6 +282,18 @@ describe Projects::MergeRequestsController do ...@@ -282,6 +282,18 @@ describe Projects::MergeRequestsController do
expect(response).to match_response_schema('entities/merge_request') expect(response).to match_response_schema('entities/merge_request')
end end
end end
context 'number of queries' do
it 'verifies number of queries' do
# pre-create objects
merge_request
recorded = ActiveRecord::QueryRecorder.new { go(format: :json) }
expect(recorded.count).to be_within(1).of(100)
expect(recorded.cached_count).to eq(0)
end
end
end end
describe "as diff" do describe "as diff" do
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"properties" : { "properties" : {
"id": { "type": "integer" }, "id": { "type": "integer" },
"iid": { "type": "integer" }, "iid": { "type": "integer" },
"assignee_id": { "type": ["integer", "null"] },
"author_id": { "type": "integer" }, "author_id": { "type": "integer" },
"description": { "type": ["string", "null"] }, "description": { "type": ["string", "null"] },
"lock_version": { "type": ["string", "null"] }, "lock_version": { "type": ["string", "null"] },
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"human_time_estimate": { "type": ["string", "null"] }, "human_time_estimate": { "type": ["string", "null"] },
"human_total_time_spent": { "type": ["string", "null"] }, "human_total_time_spent": { "type": ["string", "null"] },
"merge_error": { "type": ["string", "null"] }, "merge_error": { "type": ["string", "null"] },
"rebase_in_progress": { "type": "boolean" } "rebase_in_progress": { "type": "boolean" },
"assignee_id": { "type": ["integer", "null"] }
}, },
"additionalProperties": false "additionalProperties": false
} }
...@@ -227,13 +227,11 @@ describe('mrWidgetOptions', () => { ...@@ -227,13 +227,11 @@ describe('mrWidgetOptions', () => {
describe('handleMounted', () => { describe('handleMounted', () => {
it('should call required methods to do the initial kick-off', () => { it('should call required methods to do the initial kick-off', () => {
spyOn(vm, 'checkStatus');
spyOn(vm, 'initDeploymentsPolling'); spyOn(vm, 'initDeploymentsPolling');
spyOn(vm, 'setFavicon'); spyOn(vm, 'setFavicon');
vm.handleMounted(); vm.handleMounted();
expect(vm.checkStatus).toHaveBeenCalled();
expect(vm.setFavicon).toHaveBeenCalled(); expect(vm.setFavicon).toHaveBeenCalled();
expect(vm.initDeploymentsPolling).toHaveBeenCalled(); expect(vm.initDeploymentsPolling).toHaveBeenCalled();
}); });
......
...@@ -243,7 +243,6 @@ describe 'project routing' do ...@@ -243,7 +243,6 @@ describe 'project routing' do
# diffs_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/diffs(.:format) projects/merge_requests#diffs # diffs_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/diffs(.:format) projects/merge_requests#diffs
# commits_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/commits(.:format) projects/merge_requests#commits # commits_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/commits(.:format) projects/merge_requests#commits
# merge_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/merge(.:format) projects/merge_requests#merge # merge_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/merge(.:format) projects/merge_requests#merge
# merge_check_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/merge_check(.:format) projects/merge_requests#merge_check
# ci_status_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/ci_status(.:format) projects/merge_requests#ci_status # ci_status_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/ci_status(.:format) projects/merge_requests#ci_status
# toggle_subscription_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/toggle_subscription(.:format) projects/merge_requests#toggle_subscription # toggle_subscription_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/toggle_subscription(.:format) projects/merge_requests#toggle_subscription
# branch_from_namespace_project_merge_requests GET /:namespace_id/:project_id/merge_requests/branch_from(.:format) projects/merge_requests#branch_from # branch_from_namespace_project_merge_requests GET /:namespace_id/:project_id/merge_requests/branch_from(.:format) projects/merge_requests#branch_from
...@@ -272,10 +271,6 @@ describe 'project routing' do ...@@ -272,10 +271,6 @@ describe 'project routing' do
) )
end end
it 'to #merge_check' do
expect(get('/gitlab/gitlabhq/merge_requests/1/merge_check')).to route_to('projects/merge_requests#merge_check', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1')
end
it 'to #branch_from' do it 'to #branch_from' do
expect(get('/gitlab/gitlabhq/merge_requests/branch_from')).to route_to('projects/merge_requests#branch_from', namespace_id: 'gitlab', project_id: 'gitlabhq') expect(get('/gitlab/gitlabhq/merge_requests/branch_from')).to route_to('projects/merge_requests#branch_from', namespace_id: 'gitlab', project_id: 'gitlabhq')
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