module ActiveRecord
def self.after_all_transactions_commit(&block)
if and once all of them have been committed. But note that nesting transactions across
If multiple transactions are open across multiple databases, the block will be invoked
If any of the currently open transactions is rolled back, the block is never called.
has been committed,
If there are multiple nested transactions, the block is called after the outermost one
If there is no currently open transaction, the block is called immediately.
committed.
Registers a block to be called after all the current transactions have been
def self.after_all_transactions_commit(&block) open_transactions = all_open_transactions if open_transactions.empty? yield elsif open_transactions.size == 1 open_transactions.first.after_commit(&block) else count = open_transactions.size callback = -> do count -= 1 block.call if count.zero? end open_transactions.each do |t| t.after_commit(&callback) end open_transactions = nil # rubocop:disable Lint/UselessAssignment avoid holding it in the closure end end
def self.all_open_transactions # :nodoc:
def self.all_open_transactions # :nodoc: open_transactions = [] Base.connection_handler.each_connection_pool do |pool| if active_connection = pool.active_connection current_transaction = active_connection.current_transaction if current_transaction.open? && current_transaction.joinable? && !current_transaction.state.invalidated? open_transactions << current_transaction end end end open_transactions end
def self.db_warnings_action=(action)
def self.db_warnings_action=(action) @db_warnings_action = case action when :ignore nil when :log ->(warning) do warning_message = "[#{warning.class}] #{warning.message}" warning_message += " (#{warning.code})" if warning.code ActiveRecord::Base.logger.warn(warning_message) end when :raise ->(warning) { raise warning } when :report ->(warning) { Rails.error.report(warning, handled: true) } when Proc action else raise ArgumentError, "db_warnings_action must be one of :ignore, :log, :raise, :report, or a custom proc." end end
def self.default_timezone=(default_timezone)
Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
def self.default_timezone=(default_timezone) unless %i(local utc).include?(default_timezone) raise ArgumentError, "default_timezone must be either :utc (default) or :local." end @default_timezone = default_timezone end
def self.deprecator # :nodoc:
def self.deprecator # :nodoc: @deprecator ||= ActiveSupport::Deprecation.new end
def self.disconnect_all!
def self.disconnect_all! ConnectionAdapters::PoolConfig.disconnect_all! end
def self.eager_load!
def self.eager_load! super ActiveRecord::Locking.eager_load! ActiveRecord::Scoping.eager_load! ActiveRecord::Associations.eager_load! ActiveRecord::AttributeMethods.eager_load! ActiveRecord::ConnectionAdapters.eager_load! ActiveRecord::Encryption.eager_load! end
def self.gem_version
def self.gem_version Gem::Version.new VERSION::STRING end
def self.global_executor_concurrency # :nodoc:
def self.global_executor_concurrency # :nodoc: @global_executor_concurrency ||= nil end
def self.global_executor_concurrency=(global_executor_concurrency)
Set the +global_executor_concurrency+. This configuration value can only be used
def self.global_executor_concurrency=(global_executor_concurrency) if self.async_query_executor.nil? || self.async_query_executor == :multi_thread_pool raise ArgumentError, "`global_executor_concurrency` cannot be set when the executor is nil or set to `:multi_thread_pool`. For multiple thread pools, please set the concurrency in your database configuration." end @global_executor_concurrency = global_executor_concurrency end
def self.global_thread_pool_async_query_executor # :nodoc:
def self.global_thread_pool_async_query_executor # :nodoc: concurrency = global_executor_concurrency || 4 @global_thread_pool_async_query_executor ||= Concurrent::ThreadPoolExecutor.new( min_threads: 0, max_threads: concurrency, max_queue: concurrency * 4, fallback_policy: :caller_runs ) end
def self.marshalling_format_version
def self.marshalling_format_version Marshalling.format_version end
def self.marshalling_format_version=(value)
def self.marshalling_format_version=(value) Marshalling.format_version = value end
def self.permanent_connection_checkout=(value)
def self.permanent_connection_checkout=(value) unless [true, :deprecated, :disallowed].include?(value) raise ArgumentError, "permanent_connection_checkout must be one of: `true`, `:deprecated` or `:disallowed`" end @permanent_connection_checkout = value end
def self.schema_cache_ignored_table?(table_name)
ActiveRecord.schema_cache_ignored_table?(:developers)
against the +schema_cache_ignored_tables+ option.
Checks to see if the +table_name+ is ignored by checking
def self.schema_cache_ignored_table?(table_name) ActiveRecord.schema_cache_ignored_tables.any? do |ignored| ignored === table_name end end
def self.version
def self.version gem_version end