Sha256: 12da23bb4201616b2eb7bcfe5132f600b37b87c83a766d1d155e6656ed7307f1

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

module ActiveRecordSlave
  module InstanceMethods

    # Database Adapter method #select is called for every select call
    # Replace #select with one that calls the slave connection instead
    def select_with_slave_reader(sql, name = nil)
      # Only read from slave when not in a transaction and when this is not already the slave connection
      if (open_transactions == 0) && (Thread.current[:active_record_slave] != :master)
        ActiveRecordSlave.read_from_master do
          Slave.connection.select(sql, "Slave: #{name || 'SQL'}")
        end
      else
        select_without_slave_reader(sql, name)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_record_slave-0.2.0 lib/active_record_slave/instance_methods.rb