Db Connection Not Closed (ARCH6084)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key ruby.performance.db-connection-not-closed · Severity error · Category performance
A database connection or cursor that is opened but never closed exhausts the pool and later requests block waiting for a connection. Manage the connection with the block form.
Incorrect
Section titled “Incorrect”def count_users(pool) conn = pool.checkout conn.exec("SELECT COUNT(*) FROM users").firstendCorrect
Section titled “Correct”def count_users(pool) pool.with do |conn| conn.exec("SELECT COUNT(*) FROM users").first endendManage connections and cursors with a block/ensure form and return them to the pool when done.