Skip to content

Commit ac12b55

Browse files
committed
PYTHON-4780 Implement fast path for server selection with Primary
1 parent 0b2900d commit ac12b55

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pymongo/topology_description.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ def apply_selector(
324324
description = self.server_descriptions().get(address)
325325
return [description] if description else []
326326

327+
# Primary selection fast path.
328+
if self.topology_type == TOPOLOGY_TYPE.ReplicaSetWithPrimary and isinstance(
329+
selector, TOPOLOGY_TYPE.Primary
330+
):
331+
for sd in self._server_descriptions.values():
332+
if sd.server_type == SERVER_TYPE.RSPrimary:
333+
return [sd]
334+
327335
selection = Selection.from_topology_description(self)
328336
# Ignore read preference for sharded clusters.
329337
if self.topology_type != TOPOLOGY_TYPE.Sharded:

0 commit comments

Comments
 (0)