Commit 55dcfa3e authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'fj-refactor-snippets-create-service' into 'master'

Move repository creation outside snippet db transaction

See merge request gitlab-org/gitlab!27736
parents a4e28cd3 5fa4b5dc
...@@ -38,19 +38,16 @@ module Snippets ...@@ -38,19 +38,16 @@ module Snippets
private private
def save_and_commit(snippet) def save_and_commit(snippet)
result = snippet.with_transaction_returning_status do snippet_saved = snippet.with_transaction_returning_status do
(snippet.save && snippet.store_mentions!).tap do |saved| snippet.save && snippet.store_mentions!
break false unless saved
if Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet)
end
end
end end
create_commit(snippet) if result && snippet.repository_exists? if snippet_saved && Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet)
create_commit(snippet)
end
result snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ... rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet.errors.add(:base, e.message) snippet.errors.add(:base, e.message)
......
...@@ -193,6 +193,12 @@ describe Snippets::CreateService do ...@@ -193,6 +193,12 @@ describe Snippets::CreateService do
subject subject
end end
it 'destroys the snippet_repository' do
subject
expect(SnippetRepository.count).to be_zero
end
it 'returns the error' do it 'returns the error' do
response = subject response = subject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment