Skip to content

Commit 1074e23

Browse files
PHPLIB-1563 and PHPLIB-1564: batchSize and singleBatch fixes for find operations
* PHPLIB-1564: Increase batchSize for find when it's equal to limit * PHPLIB-1563: set singleBatch option for findOne * Bump tests/specifications from `a32d445` to `11022ca` Bumps [tests/specifications](https://github.com/mongodb/specifications) from `a32d445` to `11022ca`. - [Release notes](https://github.com/mongodb/specifications/releases) - [Commits](mongodb/specifications@a32d445...11022ca) --- updated-dependencies: - dependency-name: tests/specifications dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andreas Braun <[email protected]>
1 parent 65f7d5e commit 1074e23

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Operation/Find.php

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use MongoDB\Exception\UnsupportedException;
3131
use MongoDB\Model\CodecCursor;
3232

33+
use function assert;
3334
use function is_array;
3435
use function is_bool;
3536
use function is_integer;
@@ -418,6 +419,16 @@ private function createQueryOptions(): array
418419
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
419420
}
420421

422+
// Ensure no cursor is left behind when limit == batchSize by increasing batchSize
423+
if (isset($options['limit'], $options['batchSize']) && $options['limit'] === $options['batchSize']) {
424+
assert(is_integer($options['batchSize']));
425+
$options['batchSize']++;
426+
}
427+
428+
if (isset($options['limit']) && $options['limit'] === 1) {
429+
$options['singleBatch'] = true;
430+
}
431+
421432
return $options;
422433
}
423434
}

tests/specifications

Submodule specifications updated 65 files

0 commit comments

Comments
 (0)