Skip to content

Speed up `all_commit_shas` for new merge requests

Sean McGivern requested to merge speed-up-merge-request-all-commits-shas into master

What does this MR do?

Dramatically - 🎭 - speed up MergeRequest#all_commit_shas when the MR has commits in the new table added in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12527.

Are there points in the code the reviewer needs to double check?

I thought this would be a more clunky interface change, but actually it's pretty OK!

Why was this MR needed?

Using mixed from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12527#note_34317014:

# New method
Benchmark.realtime { 10.times { mixed.all_commit_shas } }
#=> 43.5131490000058

# Old method
Benchmark.realtime { 10.times { mixed.merge_request_diffs.preload(:merge_request_diff_commits).flat_map(&:commit_shas).uniq } }
#=> 62.56671699997969

# Just for fun!
Benchmark.realtime { 10.times { new.all_commit_shas } }
#=> 0.3927479999838397

Screenshots (if relevant)

Does this MR meet the acceptance criteria?

Edited by Sean McGivern

Merge request reports