Merge pull request #4784 from okriuchykhin/ok_SCI_7703

Improve handling of db locks [SCI-7703]
This commit is contained in:
Alex Kriuchykhin 2023-01-18 10:24:52 +01:00 committed by GitHub
commit f455b8fb32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 25 deletions

View file

@ -332,13 +332,19 @@ class ExperimentsController < ApplicationController
dst_experiment = @experiment.project.experiments.find(params[:to_experiment_id])
return render_403 unless can_manage_experiment?(dst_experiment)
@experiment.with_lock do
@experiment.transaction do
params[:my_module_ids].each do |id|
my_module = @experiment.my_modules.find(id)
return render_403 unless can_move_my_module?(my_module)
modules_to_move[id] = dst_experiment.id
end
# Make sure that locks are acquired always in the same order
if dst_experiment.id < @experiment.id
dst_experiment.lock! && @experiment.lock!
else
@experiment.lock! && dst_experiment.lock!
end
@experiment.move_modules(modules_to_move, current_user)
@experiment.workflowimg.purge

View file

@ -1,4 +1,3 @@
class ProtocolsController < ApplicationController
include RenamingUtil
include ActionView::Helpers::TextHelper
@ -165,7 +164,6 @@ class ProtocolsController < ApplicationController
end
def show
respond_to do |format|
format.json { render json: @protocol, serializer: ProtocolSerializer, user: current_user }
format.html
@ -253,9 +251,7 @@ class ProtocolsController < ApplicationController
end
def delete_steps
@protocol.my_module.lock!
Protocol.transaction do
@protocol.with_lock do
team = @protocol.team
previous_size = 0
@protocol.steps.each do |step|
@ -273,7 +269,6 @@ class ProtocolsController < ApplicationController
# skip adjusting positions after destroy as this is a bulk delete
step.skip_position_adjust = true
step.destroy!
end

View file

@ -13,9 +13,6 @@ class MyModule < ApplicationRecord
include Assignable
include Cloneable
ID_PREFIX = 'TA'
include PrefixedIdModel
attr_accessor :transition_error_rollback
enum state: Extends::TASKS_STATES

View file

@ -86,23 +86,19 @@ module RepositoryRows
return [] unless params[:rows_to_assign]
my_module.with_lock do
unassigned_rows = @repository.repository_rows
.active
.joins("LEFT OUTER JOIN my_module_repository_rows "\
"ON repository_rows.id = my_module_repository_rows.repository_row_id "\
"AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}")
.where(my_module_repository_rows: { id: nil })
.where(id: @params[:rows_to_assign])
unassigned_rows = @repository.repository_rows
.active
.joins("LEFT OUTER JOIN my_module_repository_rows " \
"ON repository_rows.id = my_module_repository_rows.repository_row_id " \
"AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}")
.where(my_module_repository_rows: { id: nil })
.where(id: @params[:rows_to_assign])
return [] unless unassigned_rows.any?
return [] unless unassigned_rows.any?
unassigned_rows.find_each do |repository_row|
MyModuleRepositoryRow.create!(my_module: my_module,
repository_row: repository_row,
assigned_by: @user)
assigned_names << repository_row.name
end
unassigned_rows.find_each do |repository_row|
my_module.my_module_repository_rows.create!(repository_row: repository_row, assigned_by: @user)
assigned_names << repository_row.name
end
return [] if assigned_names.blank?