mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Merge pull request #4784 from okriuchykhin/ok_SCI_7703
Improve handling of db locks [SCI-7703]
This commit is contained in:
commit
f455b8fb32
|
@ -332,13 +332,19 @@ class ExperimentsController < ApplicationController
|
||||||
dst_experiment = @experiment.project.experiments.find(params[:to_experiment_id])
|
dst_experiment = @experiment.project.experiments.find(params[:to_experiment_id])
|
||||||
return render_403 unless can_manage_experiment?(dst_experiment)
|
return render_403 unless can_manage_experiment?(dst_experiment)
|
||||||
|
|
||||||
@experiment.with_lock do
|
@experiment.transaction do
|
||||||
params[:my_module_ids].each do |id|
|
params[:my_module_ids].each do |id|
|
||||||
my_module = @experiment.my_modules.find(id)
|
my_module = @experiment.my_modules.find(id)
|
||||||
return render_403 unless can_move_my_module?(my_module)
|
return render_403 unless can_move_my_module?(my_module)
|
||||||
|
|
||||||
modules_to_move[id] = dst_experiment.id
|
modules_to_move[id] = dst_experiment.id
|
||||||
end
|
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.move_modules(modules_to_move, current_user)
|
||||||
@experiment.workflowimg.purge
|
@experiment.workflowimg.purge
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
class ProtocolsController < ApplicationController
|
class ProtocolsController < ApplicationController
|
||||||
include RenamingUtil
|
include RenamingUtil
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
@ -165,7 +164,6 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { render json: @protocol, serializer: ProtocolSerializer, user: current_user }
|
format.json { render json: @protocol, serializer: ProtocolSerializer, user: current_user }
|
||||||
format.html
|
format.html
|
||||||
|
@ -253,9 +251,7 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_steps
|
def delete_steps
|
||||||
@protocol.my_module.lock!
|
@protocol.with_lock do
|
||||||
|
|
||||||
Protocol.transaction do
|
|
||||||
team = @protocol.team
|
team = @protocol.team
|
||||||
previous_size = 0
|
previous_size = 0
|
||||||
@protocol.steps.each do |step|
|
@protocol.steps.each do |step|
|
||||||
|
@ -273,7 +269,6 @@ class ProtocolsController < ApplicationController
|
||||||
|
|
||||||
# skip adjusting positions after destroy as this is a bulk delete
|
# skip adjusting positions after destroy as this is a bulk delete
|
||||||
step.skip_position_adjust = true
|
step.skip_position_adjust = true
|
||||||
|
|
||||||
step.destroy!
|
step.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,6 @@ class MyModule < ApplicationRecord
|
||||||
include Assignable
|
include Assignable
|
||||||
include Cloneable
|
include Cloneable
|
||||||
|
|
||||||
ID_PREFIX = 'TA'
|
|
||||||
include PrefixedIdModel
|
|
||||||
|
|
||||||
attr_accessor :transition_error_rollback
|
attr_accessor :transition_error_rollback
|
||||||
|
|
||||||
enum state: Extends::TASKS_STATES
|
enum state: Extends::TASKS_STATES
|
||||||
|
|
|
@ -86,11 +86,10 @@ module RepositoryRows
|
||||||
|
|
||||||
return [] unless params[:rows_to_assign]
|
return [] unless params[:rows_to_assign]
|
||||||
|
|
||||||
my_module.with_lock do
|
|
||||||
unassigned_rows = @repository.repository_rows
|
unassigned_rows = @repository.repository_rows
|
||||||
.active
|
.active
|
||||||
.joins("LEFT OUTER JOIN my_module_repository_rows "\
|
.joins("LEFT OUTER JOIN my_module_repository_rows " \
|
||||||
"ON repository_rows.id = my_module_repository_rows.repository_row_id "\
|
"ON repository_rows.id = my_module_repository_rows.repository_row_id " \
|
||||||
"AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}")
|
"AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}")
|
||||||
.where(my_module_repository_rows: { id: nil })
|
.where(my_module_repository_rows: { id: nil })
|
||||||
.where(id: @params[:rows_to_assign])
|
.where(id: @params[:rows_to_assign])
|
||||||
|
@ -98,12 +97,9 @@ module RepositoryRows
|
||||||
return [] unless unassigned_rows.any?
|
return [] unless unassigned_rows.any?
|
||||||
|
|
||||||
unassigned_rows.find_each do |repository_row|
|
unassigned_rows.find_each do |repository_row|
|
||||||
MyModuleRepositoryRow.create!(my_module: my_module,
|
my_module.my_module_repository_rows.create!(repository_row: repository_row, assigned_by: @user)
|
||||||
repository_row: repository_row,
|
|
||||||
assigned_by: @user)
|
|
||||||
assigned_names << repository_row.name
|
assigned_names << repository_row.name
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return [] if assigned_names.blank?
|
return [] if assigned_names.blank?
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue