fix: frappe.conf.disable_database_connection_pooling
For the times you don't want to use pooling ;) Calling get_connection/connect will close all pooled connections for the current process / worker!
This commit is contained in:
parent
dae57d0de2
commit
363708d7f2
1 changed files with 15 additions and 0 deletions
|
|
@ -145,9 +145,24 @@ class MariaDBDatabase(Database, MariaDBExceptionUtil):
|
|||
}
|
||||
|
||||
def get_connection(self):
|
||||
"""Return MariaDB connection object.
|
||||
|
||||
If frappe.conf.disable_database_connection_pooling is set, return a new connection
|
||||
object and close existing pool if exists. Else, return a connection from the pool.
|
||||
"""
|
||||
# get pooled connection
|
||||
global _SITE_POOLS
|
||||
|
||||
if frappe.conf.disable_database_connection_pooling:
|
||||
if frappe.local.site in _SITE_POOLS:
|
||||
pool = _SITE_POOLS[frappe.local.site]
|
||||
try:
|
||||
pool.close()
|
||||
except Exception:
|
||||
pass
|
||||
_SITE_POOLS.pop(frappe.local.site, None)
|
||||
return self.create_connection()
|
||||
|
||||
if frappe.local.site not in _SITE_POOLS:
|
||||
pool = mariadb.ConnectionPool(
|
||||
pool_name=f"{frappe.local.site}_conn_pool",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue