app/models/internal_id.rb
# Create InternalId record for (scope, usage) combination, if it doesn't exist
#
# We blindly insert without synchronization. If another process
# was faster in doing this, we'll realize once we hit the unique key constraint
# violation. We can safely roll-back the nested transaction and perform
# a lookup instead to retrieve the record.
Create InternalId record for (scope, usage) combination, if it doesn't exist
We blindly insert without synchronization. If another process
was faster in doing this, we'll realize once we hit the unique key constraint
violation. We can safely roll-back the nested transaction and perform
a lookup instead to retrieve the record.
Create InternalId record for ( scope usage ) combination if it doesn ' t exist We blindly insert without synchronization . If another process was faster in doing this we ' ll realize once we hit the unique key constraint violation . We can safely roll - back the nested transaction and perform a lookup instead to retrieve the record .
def create_record(init)
      subject.transaction(requires_new: true) do
        InternalId.create!(
          **scope,
          usage: usage_value,
          last_value: init.call(subject) || 0
        )
      end
    rescue ActiveRecord::RecordNotUnique
      lookup
    end
def create_record ( init ) subject . transaction ( requires_new : true ) do InternalId . create! ( ** scope , usage : usage_value , last_value : init . call ( subject ) || 0 ) end rescue ActiveRecord :: RecordNotUnique lookup end
Create InternalId record for (scope, usage) combination, if it doesn't exist
We blindly insert without synchronization.
Create InternalId record for ( scope usage ) combination if it doesn ' t exist We blindly insert without synchronization .
init
<not_specific>