PYTHON-4347 Improve performance by only calling get_topology once (#1673)
This commit is contained in:
parent
76f1221e22
commit
5dd6ffbbb8
@ -854,6 +854,7 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
server_monitoring_mode=options.server_monitoring_mode,
|
||||
)
|
||||
|
||||
self._opened = False
|
||||
self._init_background()
|
||||
|
||||
if _IS_SYNC and connect:
|
||||
@ -1528,9 +1529,11 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
If this client was created with "connect=False", calling _get_topology
|
||||
launches the connection process in the background.
|
||||
"""
|
||||
await self._topology.open()
|
||||
async with self._lock:
|
||||
self._kill_cursors_executor.open()
|
||||
if not self._opened:
|
||||
await self._topology.open()
|
||||
async with self._lock:
|
||||
self._kill_cursors_executor.open()
|
||||
self._opened = True
|
||||
return self._topology
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
|
||||
@ -853,6 +853,7 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
server_monitoring_mode=options.server_monitoring_mode,
|
||||
)
|
||||
|
||||
self._opened = False
|
||||
self._init_background()
|
||||
|
||||
if _IS_SYNC and connect:
|
||||
@ -1527,9 +1528,11 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
If this client was created with "connect=False", calling _get_topology
|
||||
launches the connection process in the background.
|
||||
"""
|
||||
self._topology.open()
|
||||
with self._lock:
|
||||
self._kill_cursors_executor.open()
|
||||
if not self._opened:
|
||||
self._topology.open()
|
||||
with self._lock:
|
||||
self._kill_cursors_executor.open()
|
||||
self._opened = True
|
||||
return self._topology
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
Loading…
Reference in New Issue
Block a user