DEV: Remove cache PG connection type map freedom patch (#26153)

Why this change?

Previously, we identified that ActiveRecord's PostgreSQL adapter
executes 3 db queries each time a new connection is created. The 3 db
queries was identified when we looked at the `pg_stats_statement` table
on one of our multisite production cluster. At that time, the hypothesis
is that because we were agressively reaping and creating connections,
the db queries executed each time a connection is created is wasting
resources on our database servers. However, we didn't see any the needle
move much on our servers after deploying the patch so we have decided to
drop this patch as it makes it harder for us to upgrade ActiveRecord in
the future.
This commit is contained in:
Alan Guo Xiang Tan
2024-03-13 13:28:06 +08:00
committed by GitHub
parent e7f539df10
commit 1f71db426e
2 changed files with 0 additions and 74 deletions

View File

@ -1,24 +0,0 @@
# frozen_string_literal: true
RSpec.describe "Caching PostgreSQL connection type map" do
it "caches the type map and avoid querying the database for type map information on every new connection" do
expect(ActiveRecord::Base.connection.class.type_map).to be_present
pg_type_queries = []
subscriber =
ActiveSupport::Notifications.subscribe("sql.active_record") do |*, payload|
if payload[:name] == "SCHEMA"
sql = payload[:sql]
pg_type_queries.push(sql) if sql.include?("pg_type")
end
end
expect do
ActiveRecord::Base.clear_active_connections!
ActiveRecord::Base.establish_connection
end.to change { pg_type_queries.length }.by(1) # There is some default pg_type query but if stuff was not cached, we would see 4 queries here
ensure
ActiveSupport::Notifications.unsubscribe(subscriber)
end
end