diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2014-11-12 14:10:07 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2014-11-12 14:10:07 +0000 |
commit | 3898c8c21ca08517553bb0987482eb9bd66e4421 (patch) | |
tree | 79e16e35daf23a812fe79c9846c949e275ed21f0 | |
parent | 53f05343f55c1324fb73a63b972db674050941ed (diff) | |
parent | 722d80739b6b4eb6e4803fc55f750300d66b94be (diff) | |
download | gitlab-ce-3898c8c21ca08517553bb0987482eb9bd66e4421.tar.gz |
Merge branch 'performance-improvements' into 'master'
Performance improvements
Push 1k commits cause 1k sql queries to collect commit author. But this variable was used only in 20 commits (from 1000).
So we did 980 sql queries without using it. This MR fixes it.
See merge request !1250
-rw-r--r-- | app/services/git_push_service.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 3f5222c93f1..529af1970f6 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -83,9 +83,14 @@ class GitPushService # closing regex. Exclude any mentioned Issues from cross-referencing even if the commits are being pushed to # a different branch. issues_to_close = commit.closes_issues(project) - author = commit_user(commit) - if !issues_to_close.empty? && is_default_branch + # Load commit author only if needed. + # For push with 1k commits it prevents 900+ requests in database + author = nil + + if issues_to_close.present? && is_default_branch + author ||= commit_user(commit) + issues_to_close.each do |issue| Issues::CloseService.new(project, author, {}).execute(issue, commit) end @@ -96,8 +101,13 @@ class GitPushService # being pushed to a different branch). refs = commit.references(project) - issues_to_close refs.reject! { |r| commit.has_mentioned?(r) } - refs.each do |r| - Note.create_cross_reference_note(r, commit, author, project) + + if refs.present? + author ||= commit_user(commit) + + refs.each do |r| + Note.create_cross_reference_note(r, commit, author, project) + end end end end |