Commit 664ff342 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'master' into ce-to-ee-2017-12-12

parents 84c5f4e0 89d7678f
......@@ -9,6 +9,7 @@ class MergeRequest < ActiveRecord::Base
include ManualInverseAssociation
include EachBatch
include ThrottledTouch
include Gitlab::Utils::StrongMemoize
ignore_column :locked_at,
:ref_fetched
......@@ -56,6 +57,7 @@ class MergeRequest < ActiveRecord::Base
serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize
after_create :ensure_merge_request_diff, unless: :importing?
after_update :clear_memoized_shas
after_update :reload_diff_if_branch_changed
# When this attribute is true some MR validation is ignored
......@@ -404,14 +406,18 @@ class MergeRequest < ActiveRecord::Base
end
def source_branch_head
return unless source_project
source_project.repository.commit(source_branch_ref) if source_branch_ref
strong_memoize(:source_branch_head) do
if source_project && source_branch_ref
source_project.repository.commit(source_branch_ref)
end
end
end
def target_branch_head
strong_memoize(:target_branch_head) do
target_project.repository.commit(target_branch_ref)
end
end
def branch_merge_base_commit
start_sha = target_branch_sha
......@@ -558,6 +564,13 @@ class MergeRequest < ActiveRecord::Base
end
end
def clear_memoized_shas
@target_branch_sha = @source_branch_sha = nil
clear_memoization(:source_branch_head)
clear_memoization(:target_branch_head)
end
def reload_diff_if_branch_changed
if (source_branch_changed? || target_branch_changed?) &&
(source_branch_head && target_branch_head)
......
......@@ -104,19 +104,19 @@ class MergeRequestDiff < ActiveRecord::Base
def base_commit
return unless base_commit_sha
project.commit(base_commit_sha)
project.commit_by(oid: base_commit_sha)
end
def start_commit
return unless start_commit_sha
project.commit(start_commit_sha)
project.commit_by(oid: start_commit_sha)
end
def head_commit
return unless head_commit_sha
project.commit(head_commit_sha)
project.commit_by(oid: head_commit_sha)
end
def commit_shas
......
---
title: Cache commits for MergeRequest diffs
merge_request:
author:
type: performance
......@@ -51,6 +51,10 @@ module Gitlab
#{config.root}/ee/app/helpers
])
# Rake tasks ignore the eager loading settings, so we need to set the
# autoload paths explicitly
config.autoload_paths = config.eager_load_paths.dup
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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