1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #42368 from engwan/postgresql-empty-query-check

Use an empty query instead of SELECT 1
This commit is contained in:
Andrew White 2021-06-07 11:31:18 +01:00 committed by GitHub
commit ed3612e6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -1,3 +1,9 @@
* Use an empty query to check if the PostgreSQL connection is still active
An empty query is faster than `SELECT 1`.
*Heinrich Lee Yu*
* Add `ActiveRecord::Base#previously_persisted?`
Returns `true` if the object has been previously persisted but now it has been deleted.

View file

@ -292,7 +292,7 @@ module ActiveRecord
# Is this connection alive and ready for queries?
def active?
@lock.synchronize do
@connection.query "SELECT 1"
@connection.query ";"
end
true
rescue PG::Error