Skip to content

Commit

Permalink
PYTHON-4921 Eliminate unnecessary killCursors command when batchSize …
Browse files Browse the repository at this point in the history
…== limit
  • Loading branch information
ShaneHarvey committed Nov 15, 2024
1 parent aa24a49 commit 6b7bd02
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pymongo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def _gen_find_command(
if limit < 0:
cmd["singleBatch"] = True
if batch_size:
# When limit and batchSize are equal we increase batchSize by 1 to
# avoid an unnecessary killCursors.
if limit == batch_size:
batch_size += 1
cmd["batchSize"] = batch_size
if read_concern.level and not (session and session.in_transaction):
cmd["readConcern"] = read_concern.document
Expand Down

0 comments on commit 6b7bd02

Please sign in to comment.