From 2a9c2fec4efd1b88e2ee8ad87818d8435a97619f Mon Sep 17 00:00:00 2001
From: Stan Hu <stanhu@gmail.com>
Date: Mon, 3 Jul 2017 15:46:52 -0700
Subject: [PATCH] Optimize creation of commit API by using Repository#commit
 instead of Repository#commits

Repository#commits is expensive because it has to use Rugged to walk the Git
tree as opposed to doing a direct ref lookup.

Improves performance in #34533
---
 changelogs/unreleased/sh-optimize-project-commit-api.yml | 4 ++++
 lib/api/commits.rb                                       | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
 create mode 100644 changelogs/unreleased/sh-optimize-project-commit-api.yml

diff --git a/changelogs/unreleased/sh-optimize-project-commit-api.yml b/changelogs/unreleased/sh-optimize-project-commit-api.yml
new file mode 100644
index 00000000000..e6a8a80593c
--- /dev/null
+++ b/changelogs/unreleased/sh-optimize-project-commit-api.yml
@@ -0,0 +1,4 @@
+---
+title: Optimize creation of commit API by using Repository#commit instead of Repository#commits
+merge_request:
+author:
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index c6fc17cc391..bcb842b9211 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -67,7 +67,7 @@ module API
         result = ::Files::MultiService.new(user_project, current_user, attrs).execute
 
         if result[:status] == :success
-          commit_detail = user_project.repository.commits(result[:result], limit: 1).first
+          commit_detail = user_project.repository.commit(result[:result])
           present commit_detail, with: Entities::RepoCommitDetail
         else
           render_api_error!(result[:message], 400)
-- 
GitLab