Cache MR diffs by diff refs

This commit is contained in:
Douwe Maan 2017-03-31 17:49:43 -06:00
parent b202b42cfe
commit 2c0de7aaaf
2 changed files with 11 additions and 1 deletions

View file

@ -368,7 +368,11 @@ class MergeRequest < ActiveRecord::Base
end end
def merge_request_diff_for(diff_refs) def merge_request_diff_for(diff_refs)
merge_request_diffs.viewable.select_without_diff.with_diff_refs(diff_refs).take @merge_request_diffs_by_diff_refs ||= Hash.new do |h, diff_refs|
h[diff_refs] = merge_request_diffs.viewable.select_without_diff.with_diff_refs(diff_refs).take
end
@merge_request_diffs_by_diff_refs[diff_refs]
end end
def reload_diff_if_branch_changed def reload_diff_if_branch_changed

View file

@ -18,6 +18,12 @@ module Gitlab
head_sha == other.head_sha head_sha == other.head_sha
end end
alias_method :eql?, :==
def hash
[base_sha, start_sha, head_sha].hash
end
# There is only one case in which we will have `start_sha` and `head_sha`, # There is only one case in which we will have `start_sha` and `head_sha`,
# but not `base_sha`, which is when a diff is generated between an # but not `base_sha`, which is when a diff is generated between an
# orphaned branch and another branch, which means there _is_ no base, but # orphaned branch and another branch, which means there _is_ no base, but