mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 13:13:22 +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
4 changed files with 19 additions and 25 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue