Move repository creation outside snippet db transaction

parent 9ce3beb3
......@@ -38,19 +38,16 @@ module Snippets
private
def save_and_commit(snippet)
result = snippet.with_transaction_returning_status do
(snippet.save && snippet.store_mentions!).tap do |saved|
break false unless saved
snippet_saved = snippet.with_transaction_returning_status do
snippet.save && snippet.store_mentions!
end
if Feature.enabled?(:version_snippets, current_user)
if snippet_saved && Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet)
create_commit(snippet)
end
end
end
create_commit(snippet) if result && snippet.repository_exists?
result
snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet.errors.add(:base, e.message)
......
......@@ -193,6 +193,12 @@ describe Snippets::CreateService do
subject
end
it 'destroys the snippet_repository' do
subject
expect(SnippetRepository.count).to be_zero
end
it 'returns the error' do
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