[FIX] sql_db: only perform the connection reset when actually planning to borrow that connection, not before, for obvious performance reasons
bzr revid: odo@openerp.com-20130215161025-mjgmlju3zgs50zk7
This commit is contained in:
parent
dd945310ea
commit
547372ef94
|
@ -400,14 +400,6 @@ class ConnectionPool(object):
|
|||
|
||||
# free dead and leaked connections
|
||||
for i, (cnx, _) in tools.reverse_enumerate(self._connections):
|
||||
try:
|
||||
cnx.reset()
|
||||
except psycopg2.OperationalError:
|
||||
self._debug('Cannot reset connection at index %d: %r', i, cnx.dsn)
|
||||
# psycopg2 2.4.4 and earlier do not allow closing a closed connection
|
||||
if not cnx.closed:
|
||||
cnx.close()
|
||||
|
||||
if cnx.closed:
|
||||
self._connections.pop(i)
|
||||
self._debug('Removing closed connection at index %d: %r', i, cnx.dsn)
|
||||
|
@ -420,6 +412,14 @@ class ConnectionPool(object):
|
|||
|
||||
for i, (cnx, used) in enumerate(self._connections):
|
||||
if not used and dsn_are_equals(cnx.dsn, dsn):
|
||||
try:
|
||||
cnx.reset()
|
||||
except psycopg2.OperationalError:
|
||||
self._debug('Cannot reset connection at index %d: %r', i, cnx.dsn)
|
||||
# psycopg2 2.4.4 and earlier do not allow closing a closed connection
|
||||
if not cnx.closed:
|
||||
cnx.close()
|
||||
continue
|
||||
self._connections.pop(i)
|
||||
self._connections.append((cnx, True))
|
||||
self._debug('Existing connection found at index %d', i)
|
||||
|
|
Loading…
Reference in New Issue