[FIX] do not keep connections to template1, template0 and postgres in the connection pool

bzr revid: ach@tinyerp.com-20100513084819-4b3r2l60wla6zf1n
This commit is contained in:
Anup (OpenERP) 2010-05-13 14:18:19 +05:30
parent 9b0ec193f3
commit 9830fb430f
1 changed files with 6 additions and 3 deletions

View File

@ -194,7 +194,8 @@ class Cursor(object):
# part because browse records keep a reference to the cursor.
del self._obj
self.__closed = True
self._pool.give_back(self._cnx)
keep_in_pool = self.dbname not in ('template1', 'template0', 'postgres')
self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
@check
def autocommit(self, on):
@ -277,12 +278,14 @@ class ConnectionPool(object):
return result
@locked
def give_back(self, connection):
def give_back(self, connection, keep_in_pool=True):
self._debug('Give back connection to %s' % (connection.dsn,))
for i, (cnx, used) in enumerate(self._connections):
if cnx is connection:
self._connections.pop(i)
self._connections.append((cnx, False))
if keep_in_pool:
self._connections.append((cnx, False))
self._debug('Put connection to %s in pool' % (cnx.dsn,))
break
else:
raise PoolError('This connection does not below to the pool')