Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Created July 21, 2015 09:45
Show Gist options
  • Save mikecmpbll/b34311f61e6e695f1ec5 to your computer and use it in GitHub Desktop.
Save mikecmpbll/b34311f61e6e695f1ec5 to your computer and use it in GitHub Desktop.
Yes ActiveRecord, you will bow to me.
scope = RealModel.where(name: 'foo')
threads = []
dbs.each do |db|
threads << Thread.new do
dynamic_class_name = "TempModel#{Thread.current.object_id}"
dynamic_class = Object.const_set(dynamic_class_name, Class.new(query_model))
begin
con = retrieve_connection(db, resolver)
dynamic_class.establish_connection(con)
local_scope = dynamic_class.all.merge(scope)
results[db] = local_scope.to_a.each(&:readonly!)
ensure
dynamic_class.connection_pool.release_connection
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment