Skip to content

Commit

Permalink
Fix performance issue of DatabaseCleaner::Base#orm_module. Closes #624
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt authored and botandrose committed Feb 18, 2020
1 parent 0f4e29d commit bf53037
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/database_cleaner/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,23 @@ def create_strategy(*args)

def orm_module
return unless [:active_record, :data_mapper, :mongo, :mongoid, :mongo_mapper, :moped, :couch_potato, :sequel, :ohm, :redis, :neo4j].include?(orm)
load_adapter(orm) if !adapter_loaded?(orm)
orm_module_name = ORMAutodetector::ORMS[orm]
DatabaseCleaner.const_get(orm_module_name, false)
end

def adapter_loaded? orm
$LOADED_FEATURES.grep(%r{/lib/database_cleaner/#{orm}\.rb$}).any?
end

def load_adapter orm
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
require "database_cleaner/#{orm}"
orm_module_name = ORMAutodetector::ORMS[orm]
DatabaseCleaner.const_get(orm_module_name)
end

def orm_strategy(strategy)
strategy_module_name = strategy.to_s.capitalize
orm_module.const_get(strategy_module_name)
orm_module.const_get(strategy_module_name, false)
rescue NameError
if orm != :active_record
DatabaseCleaner.deprecate <<-TEXT
Expand Down

0 comments on commit bf53037

Please sign in to comment.