diff --git a/lib/NGCP/Panel/Controller/API/SoundFiles.pm b/lib/NGCP/Panel/Controller/API/SoundFiles.pm index 79a01d0d7f..be6ba435ce 100644 --- a/lib/NGCP/Panel/Controller/API/SoundFiles.pm +++ b/lib/NGCP/Panel/Controller/API/SoundFiles.pm @@ -53,6 +53,7 @@ sub relation{ __PACKAGE__->set_config({ allowed_roles => [qw/admin reseller subscriberadmin/], + set_transaction_isolation => 'READ COMMITTED', }); sub auto :Private { @@ -108,6 +109,7 @@ sub GET :Allow { sub POST :Allow { my ($self, $c) = @_; + $c->model('DB')->set_transaction_isolation('READ COMMITTED'); my $guard = $c->model('DB')->txn_scope_guard; { my ($recording, $resource); diff --git a/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm b/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm index d530fe3d3f..70b1b581ac 100644 --- a/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm +++ b/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm @@ -31,6 +31,7 @@ sub relation{ __PACKAGE__->set_config({ allowed_roles => [qw/admin reseller subscriberadmin/], + set_transaction_isolation => 'READ COMMITTED', }); sub GET :Allow { @@ -57,6 +58,8 @@ sub GET :Allow { sub PUT :Allow { my ($self, $c, $id) = @_; + + $c->model('DB')->set_transaction_isolation('READ COMMITTED'); my $guard = $c->model('DB')->txn_scope_guard; { my $preference = $self->require_preference($c); @@ -87,6 +90,8 @@ sub PUT :Allow { sub PATCH :Allow { my ($self, $c, $id) = @_; + + $c->model('DB')->set_transaction_isolation('READ COMMITTED'); my $guard = $c->model('DB')->txn_scope_guard; { my $preference = $self->require_preference($c); @@ -119,6 +124,7 @@ sub PATCH :Allow { sub DELETE :Allow { my ($self, $c, $id) = @_; + $c->model('DB')->set_transaction_isolation('READ COMMITTED'); my $guard = $c->model('DB')->txn_scope_guard; { my $item = $self->item_by_id($c, $id); diff --git a/lib/NGCP/Panel/Controller/API/SoundSets.pm b/lib/NGCP/Panel/Controller/API/SoundSets.pm index b109027ebf..3a2de92243 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSets.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSets.pm @@ -8,6 +8,7 @@ use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::SoundSets/; __PACKAGE__->set_config({ allowed_roles => [qw/admin reseller subscriberadmin/], + set_transaction_isolation => 'READ COMMITTED', }); sub allowed_methods{ diff --git a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm index 61293e6ad4..b363383afb 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm @@ -11,7 +11,8 @@ __PACKAGE__->set_config({ allowed_roles => { Default => [qw/admin reseller subscriberadmin/], Journal => [qw/admin reseller subscriberadmin/], - } + }, + set_transaction_isolation => 'READ COMMITTED', }); sub allowed_methods{ diff --git a/lib/NGCP/Panel/Controller/Sound.pm b/lib/NGCP/Panel/Controller/Sound.pm index c5fcd877a9..fd5570c5b9 100644 --- a/lib/NGCP/Panel/Controller/Sound.pm +++ b/lib/NGCP/Panel/Controller/Sound.pm @@ -271,6 +271,7 @@ sub edit :Chained('base') :PathPart('edit') { die "an attempt to edit a sound set that does not belong to the subscriberadmin"; } + $c->model('DB')->set_transaction_isolation('READ COMMITTED'); $c->model('DB')->txn_do(sub { if ($c->stash->{set_result}->expose_to_customer == 1 && $form->values->{expose_to_customer} == 0) { @@ -298,7 +299,7 @@ sub edit :Chained('base') :PathPart('edit') { # invalidate cache of this sound set if parent is changed if ((!$old_parent_id && $parent_id) || ($old_parent_id && !$parent_id) || - $old_parent_id != $parent_id) { + ($old_parent_id && $parent_id && $old_parent_id != $parent_id)) { NGCP::Panel::Utils::Sems::clear_audio_cache($c, $own_id); } @@ -336,6 +337,7 @@ sub delete_sound :Chained('base') :PathPart('delete') { try { my $schema = $c->model('DB'); + $schema->set_transaction_isolation('READ COMMITTED'); $schema->txn_do(sub { my $own_id = $c->stash->{set_result}->id; @@ -453,6 +455,7 @@ sub create :Chained('sets_list') :PathPart('create') :Args() { delete $form->values->{parent}; my $schema = $c->model('DB'); + $schema->set_transaction_isolation('READ COMMITTED'); $schema->txn_do(sub { # if a new contract default is set, clear old ones first if($form->values->{contract_id} && $form->values->{contract_default} == 1) { @@ -589,7 +592,6 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') { if($posted && $form->validated) { # only if the form is validated and a POST is issued, insert the sound file in the db - $file_result->insert(); if (defined $upload) { my $soundfile = eval { $upload->slurp }; my $filename = eval { $upload->filename }; @@ -619,12 +621,17 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') { } try { - $file_result->update({ - loopplay => $form->values->{loopplay}, - use_parent => $form->values->{use_parent}, - filename => $filename, - data => $soundfile, - codec => $target_codec, + my $schema = $c->model('DB'); + $schema->set_transaction_isolation('READ COMMITTED'); + $schema->txn_do(sub { + $file_result->insert(); + $file_result->update({ + loopplay => $form->values->{loopplay}, + use_parent => $form->values->{use_parent}, + filename => $filename, + data => $soundfile, + codec => $target_codec, + }); }); NGCP::Panel::Utils::Message::info( c => $c, @@ -639,9 +646,14 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') { } } else { try { - $file_result->update({ - loopplay => $form->values->{loopplay}, - use_parent => $form->values->{use_parent}, + my $schema = $c->model('DB'); + $schema->set_transaction_isolation('READ COMMITTED'); + $schema->txn_do(sub { + $file_result->insert(); + $file_result->update({ + loopplay => $form->values->{loopplay}, + use_parent => $form->values->{use_parent}, + }); }); NGCP::Panel::Utils::Message::info( c => $c, @@ -683,7 +695,11 @@ sub handles_delete :Chained('handles_base') :PathPart('delete') { $self->check_subadmin_handle_edit_access($c, $c->stash->{file_result}); try { - $c->stash->{file_result}->delete; + my $schema = $c->model('DB'); + $schema->set_transaction_isolation('READ COMMITTED'); + $schema->txn_do(sub { + $c->stash->{file_result}->delete; + }); NGCP::Panel::Utils::Message::info( c => $c, data => { $c->stash->{file_result}->get_inflated_columns }, diff --git a/lib/NGCP/Panel/Role/API/SoundSets.pm b/lib/NGCP/Panel/Role/API/SoundSets.pm index b4c4a658b8..b2cbae6ad5 100644 --- a/lib/NGCP/Panel/Role/API/SoundSets.pm +++ b/lib/NGCP/Panel/Role/API/SoundSets.pm @@ -188,7 +188,7 @@ sub update_item_model { my $parent_id = $resource->{parent_id}; if ((!$old_parent_id && $parent_id) || ($old_parent_id && !$parent_id) || - $old_parent_id != $parent_id) { + ($old_parent_id && $parent_id && $old_parent_id != $parent_id)) { NGCP::Panel::Utils::Sems::clear_audio_cache($c, $item->id); }