Last active
May 3, 2018 16:25
-
-
Save sudoremo/89ea56cb6355b02dd2b91d4547a63318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# This file attempts to reproduce issue #1720 of the enhanced adapter | |
# (https://github.com/rsim/oracle-enhanced). See issue comments for instructions | |
# on how to use this file. | |
# CONFIGURATION | |
DB_CONFIG = { | |
adapter: :oracle_enhanced, | |
host: 'REPLACE_ME' || ENV['DB_HOST'], | |
port: REPLACE_ME || ENV['DB_PORT'], | |
database: 'REPLACE_ME' || ENV['DB_NAME'], | |
username: 'REPLACE_ME' || ENV['DB_USERNAME'], | |
password: 'REPLACE_ME' || ENV['DB_PASSWORD'] | |
}.freeze | |
# END OF CONFIGURATION | |
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'activerecord', ENV['NEW'] ? '5.2.0' : '5.1.6' | |
gem 'activerecord-oracle_enhanced-adapter', ENV['NEW'] ? '5.2.2' : '1.8.2' | |
end | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'active_record/connection_adapters/oracle_enhanced_adapter' | |
require "logger" | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
ActiveSupport.on_load(:active_record) do | |
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do | |
# See https://github.com/rsim/oracle-enhanced/issues/920 and | |
# https://github.com/rsim/oracle-enhanced/issues/1066 | |
self.use_old_oracle_visitor = true | |
end | |
end | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(DB_CONFIG) | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
TABLE_COUNT = 20 | |
COLUMN_COUNT_PER_TYPE = 10 | |
ActiveRecord::Schema.define do | |
TABLE_COUNT.times do |i| | |
create_table :"table_#{i}", force: true do |t| | |
COLUMN_COUNT_PER_TYPE.times do |j| | |
t.string :"string_column_#{j}" | |
t.integer :"integer_column_#{j}" | |
end | |
end | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_performance | |
benchmark = Benchmark.measure { | |
TABLE_COUNT.times do |i| | |
c = Class.new(ActiveRecord::Base) do | |
self.table_name = "table_#{i}" | |
end | |
c.first | |
end | |
} | |
puts "BENCHMARK:" | |
puts benchmark | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment