Skip to content

Commit 879c36a

Browse files
RUST-2071 Increase batchSize for find when batchSize == limit (#1348)
1 parent 6e041e6 commit 879c36a

File tree

9 files changed

+1052
-12
lines changed

9 files changed

+1052
-12
lines changed

src/operation/find.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
bson::{rawdoc, Document},
55
cmap::{Command, RawCommandResponse, StreamDescription},
66
cursor::CursorSpecification,
7-
error::{ErrorKind, Result},
7+
error::{Error, Result},
88
operation::{CursorBody, OperationWithDefaults, Retryability, SERVER_4_4_0_WIRE_VERSION},
99
options::{CursorType, FindOptions, SelectionCriteria},
1010
Namespace,
@@ -38,21 +38,23 @@ impl OperationWithDefaults for Find {
3838
Self::NAME: self.ns.coll.clone(),
3939
};
4040

41-
if let Some(ref options) = self.options {
41+
if let Some(ref mut options) = self.options {
4242
// negative limits should be interpreted as request for single batch as per crud spec.
4343
if options.limit.map(|limit| limit < 0) == Some(true) {
4444
body.append("singleBatch", true);
4545
}
4646

47-
if options
48-
.batch_size
49-
.map(|batch_size| batch_size > i32::MAX as u32)
50-
== Some(true)
51-
{
52-
return Err(ErrorKind::InvalidArgument {
53-
message: "The batch size must fit into a signed 32-bit integer".to_string(),
47+
if let Some(ref mut batch_size) = options.batch_size {
48+
if i32::try_from(*batch_size).is_err() {
49+
return Err(Error::invalid_argument(
50+
"the batch size must fit into a signed 32-bit integer",
51+
));
52+
}
53+
if let Some(limit) = options.limit.and_then(|limit| u32::try_from(limit).ok()) {
54+
if *batch_size == limit {
55+
*batch_size += 1;
56+
}
5457
}
55-
.into());
5658
}
5759

5860
match options.cursor_type {

0 commit comments

Comments
 (0)