Doc what with_lock does

This commit is contained in:
Pau Perez
2017-08-10 16:35:28 +02:00
committed by Rob Harrington
parent 1faa1579f3
commit a763c24f3c
2 changed files with 8 additions and 0 deletions

View File

@@ -16,6 +16,10 @@ module Admin
load_line_item
authorize_update!
# `with_lock` acquires an exclusive row lock on order so no other
# requests can update it until the transaction is commited.
# See https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/locking/pessimistic.rb#L69
# and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE
order.with_lock do
if @line_item.update_attributes(params[:line_item])
order.update_distribution_charge!

View File

@@ -181,6 +181,10 @@ Spree::Order.class_eval do
end
def update_distribution_charge!
# `with_lock` acquires an exclusive row lock on order so no other
# requests can update it until the transaction is commited.
# See https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/locking/pessimistic.rb#L69
# and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE
with_lock do
EnterpriseFee.clear_all_adjustments_on_order self