Made closing in connection handlers more DRY.
This commit is contained in:
parent
3a82b5f655
commit
20e65a34ae
|
@ -60,8 +60,7 @@ cache = ConnectionProxy(caches, DEFAULT_CACHE_ALIAS)
|
|||
def close_caches(**kwargs):
|
||||
# Some caches need to do a cleanup at the end of a request cycle. If not
|
||||
# implemented in a particular backend cache.close() is a no-op.
|
||||
for cache in caches.all(initialized_only=True):
|
||||
cache.close()
|
||||
caches.close_all()
|
||||
|
||||
|
||||
signals.request_finished.connect(close_caches)
|
||||
|
|
|
@ -190,14 +190,6 @@ class ConnectionHandler(BaseConnectionHandler):
|
|||
backend = load_backend(db["ENGINE"])
|
||||
return backend.DatabaseWrapper(db, alias)
|
||||
|
||||
def close_all(self):
|
||||
for alias in self:
|
||||
try:
|
||||
connection = getattr(self._connections, alias)
|
||||
except AttributeError:
|
||||
continue
|
||||
connection.close()
|
||||
|
||||
|
||||
class ConnectionRouter:
|
||||
def __init__(self, routers=None):
|
||||
|
|
|
@ -79,3 +79,7 @@ class BaseConnectionHandler:
|
|||
# If initialized_only is True, return only initialized connections.
|
||||
if not initialized_only or hasattr(self._connections, alias)
|
||||
]
|
||||
|
||||
def close_all(self):
|
||||
for conn in self.all(initialized_only=True):
|
||||
conn.close()
|
||||
|
|
Loading…
Reference in New Issue