Skip to content

Commit 2c0de7a

Browse files
committed
Cache MR diffs by diff refs
1 parent b202b42 commit 2c0de7a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/models/merge_request.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ def reload_merge_request_diff
368368
end
369369

370370
def merge_request_diff_for(diff_refs)
371-
merge_request_diffs.viewable.select_without_diff.with_diff_refs(diff_refs).take
371+
@merge_request_diffs_by_diff_refs ||= Hash.new do |h, diff_refs|
372+
h[diff_refs] = merge_request_diffs.viewable.select_without_diff.with_diff_refs(diff_refs).take
373+
end
374+
375+
@merge_request_diffs_by_diff_refs[diff_refs]
372376
end
373377

374378
def reload_diff_if_branch_changed

lib/gitlab/diff/diff_refs.rb

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def ==(other)
1818
head_sha == other.head_sha
1919
end
2020

21+
alias_method :eql?, :==
22+
23+
def hash
24+
[base_sha, start_sha, head_sha].hash
25+
end
26+
2127
# There is only one case in which we will have `start_sha` and `head_sha`,
2228
# but not `base_sha`, which is when a diff is generated between an
2329
# orphaned branch and another branch, which means there _is_ no base, but

0 commit comments

Comments
 (0)