Module: GraphMediator::Locking::ClassMethods

Defined in:
lib/graph_mediator/locking.rb

Instance Method Summary collapse

Instance Method Details

#update_counters(ids, counters) ⇒ Object

Overrides ActiveRecord::Base.update_counters to skip locking if currently mediating the passed id.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graph_mediator/locking.rb', line 15

def update_counters(ids, counters)
  # id may be an array of ids...
  unless currently_mediating?(ids)
    # if none are being mediated can proceed as normal
    super
  else
    # we have to go one by one unfortunately
    Array(ids).each do |id|
      currently_mediating?(id) ?
        update_counters_without_lock(id, counters) :
        super
    end
  end
end