Avoid retrieving connection in ActiveRecord::QueryCache multiple times.
Merge pull request #16078 from tgxworld/retreive_connection_once

Avoid retrieving connection in ActiveRecord::QueryCache multiple times.