mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Switch ActiveRecord PG connection active check to use empty query. (#13323)
See https://github.com/rails/rails/pull/42368 The impact is not quantifiable at the time of this writing but prelimary investigation shows that `SELECT 1` accounts for 0.09 of CPU time on a database. Note that Discourse runs thousands of databases so the small impact may be amplified by the large number of databases that we run.
This commit is contained in:
parent
0815b4cc2e
commit
19a92fbadc
19
lib/freedom_patches/active_record_postgresql_adapter.rb
Normal file
19
lib/freedom_patches/active_record_postgresql_adapter.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Pulls in https://github.com/rails/rails/pull/42368 early since the query is
|
||||
# definitely more efficient as it does not involved the PG planner.
|
||||
# Remove once Rails 7 has been released.
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
class PostgreSQLAdapter
|
||||
def active?
|
||||
@lock.synchronize do
|
||||
@connection.query ";"
|
||||
end
|
||||
true
|
||||
rescue PG::Error
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user