Skip to content

Commit 6b7bd02

Browse files
committed
PYTHON-4921 Eliminate unnecessary killCursors command when batchSize == limit
1 parent aa24a49 commit 6b7bd02

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pymongo/message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def _gen_find_command(
252252
if limit < 0:
253253
cmd["singleBatch"] = True
254254
if batch_size:
255+
# When limit and batchSize are equal we increase batchSize by 1 to
256+
# avoid an unnecessary killCursors.
257+
if limit == batch_size:
258+
batch_size += 1
255259
cmd["batchSize"] = batch_size
256260
if read_concern.level and not (session and session.in_transaction):
257261
cmd["readConcern"] = read_concern.document

0 commit comments

Comments
 (0)