diff options
author | Stan Hu <stanhu@gmail.com> | 2019-03-03 23:33:20 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-03-03 23:40:43 -0800 |
commit | d13fcca2acc01d1fbbf6240d694fbf1bb69b073e (patch) | |
tree | 36847d53d869571d62b2735c4b5354adaa47ed0d /app/models | |
parent | 615c14b28990489d99371b7ffdb57fe54d463e64 (diff) | |
download | gitlab-ce-sh-optimize-last-commit-sha.tar.gz |
Optimize MergeRequestDiff#last_commit_shash-optimize-last-commit-sha
The previous implementation would load all the MergeRequestDiffCommit
entries into memory and retrieve the SHA from the latest entry. We can
save a bit of query time and memory by retrieving the SHA directly from
the first item from the database. This is particularly helpful when
there are many merge requests that need this information.
Seen while investigating Todo API performance in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25711.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/merge_request_diff.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index e286a4e57f2..3556448e547 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -118,7 +118,7 @@ class MergeRequestDiff < ActiveRecord::Base end def last_commit_sha - commit_shas.first + merge_request_diff_commits.first&.sha end def first_commit |