title: Rails, Puma, Postgres: Preloading Active Record definitions?
body: <p>After every boot, I see queries like these to the database:</p>
  
  <p><a href="https://i.stack.imgur.com/2AUo1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2AUo1.png" alt="enter image description here"></a></p>
  
  <p>Once each puma worker is hit once with a request (that hits the database), these go away. It's annoying because it can add 50+ sql queries to a request (1s +). What I want to do is somehow preload these every time a worker boots.</p>
  
  <p>I've tried</p>
  
  <pre><code>on_worker_boot do
    ActiveSupport.on_load(:active_record) do
      ActiveRecord::Base.establish_connection
    end
    Rails.application.eager_load!
    ::Rails::Engine.subclasses.map(&amp;:instance).each { |engine| engine.eager_load! }
    ActiveRecord::Base.descendants
  end
  </code></pre>
  
  <p>Which does not work.</p>
  
  <p>I have both</p>
  
  <pre><code>  config.cache_classes = true
    config.eager_load = true
  </code></pre>
  
  <p>set in my environment.</p>
  
  <p>I'm expecting there to be some sort of rails setting that does this - seems like a smart thing to do by default in production?</p>