summaryrefslogtreecommitdiff
path: root/app/models/merge_request_diff.rb
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-12-11 16:38:16 +0100
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2017-12-12 16:28:26 +0100
commit3ab026b7d69ec97796fe4bb409933d7a716eef19 (patch)
tree6711c10cf577250647330b1d2725e13ce2177a66 /app/models/merge_request_diff.rb
parent806a68a81f1baeed07c146b1b5d9eb77796c46ba (diff)
downloadgitlab-ce-3ab026b7d69ec97796fe4bb409933d7a716eef19.tar.gz
Use memoization for commits on diffs
The Gitaly CommitService is being hammered by n + 1 calls, mostly when finding commits. This leads to this gRPC being turned of on production: https://gitlab.com/gitlab-org/gitaly/issues/514#note_48991378 Hunting down where it came from, most of them were due to MergeRequest#show. To prove this, I set a script to request the MergeRequest#show page 50 times. The GDK was being scraped by Prometheus, where we have metrics on controller#action and their Gitaly calls performed. On both occations I've restarted the full GDK so all caches had to be rebuild. Current master, 806a68a81f1baee, needed 435 requests After this commit, 154 requests
Diffstat (limited to 'app/models/merge_request_diff.rb')
-rw-r--r--app/models/merge_request_diff.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index c37aa0a594b..e35de9b97ee 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -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