set_roll_back should only rollback initialized connections

The exception handler call "connections.all()". This creates a database connection to all defined databases. 
As a small optimization you can use "connections.all(initialized_only=True)" to rollback only the database to which the current thread has open connections.

(My application can have many databases defined, and this loop is identified as a source of many idle database connections)
This commit is contained in:
Johan De Taeye 2024-12-09 16:48:50 +01:00 committed by GitHub
parent dbac145638
commit cad0ad02db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,7 +64,7 @@ def get_view_description(view, html=False):
def set_rollback(): def set_rollback():
for db in connections.all(): for db in connections.all(initialized_only=True):
if db.settings_dict['ATOMIC_REQUESTS'] and db.in_atomic_block: if db.settings_dict['ATOMIC_REQUESTS'] and db.in_atomic_block:
db.set_rollback(True) db.set_rollback(True)