Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-multi-tenant/with_lock.rb

Overview

Workaround for github.com/citusdata/citus/issues/1236 “SELECT … FOR UPDATE is not supported for router-plannable queries”

Instance Method Summary collapse

Instance Method Details

#lock!(lock = true) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/activerecord-multi-tenant/with_lock.rb', line 6

def lock!(lock = true)
  if lock && persisted? && self.class.respond_to?(:scoped_by_tenant?) && MultiTenant.current_tenant_id && MultiTenant.with_lock_workaround_enabled?
    self.class.unscoped.where(id: id).update_all(id: id) # No-op UPDATE that locks the row
    reload # This is just to act similar to the default ActiveRecord approach, in case someone relies on the reload
    self
  else
    lock_orig(lock)
  end
end

#lock_origObject


5
# File 'lib/activerecord-multi-tenant/with_lock.rb', line 5

alias :lock_orig :lock!