Skip to content

Commit 7309996

Browse files
committed
Support query timeout as decimal number of seconds
1 parent 3b98a3f commit 7309996

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/Query/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function project($columns)
212212
/**
213213
* The maximum amount of seconds to allow the query to run.
214214
*
215-
* @param int $seconds
215+
* @param int|float $seconds
216216
*
217217
* @return $this
218218
*/
@@ -441,7 +441,7 @@ public function toMql(): array
441441

442442
// Apply order, offset, limit and projection
443443
if ($this->timeout) {
444-
$options['maxTimeMS'] = $this->timeout * 1000;
444+
$options['maxTimeMS'] = round($this->timeout * 1000);
445445
}
446446

447447
if ($this->orders) {

Diff for: tests/Query/BuilderTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,11 @@ function (Builder $elemMatchQuery): void {
14371437
['find' => [[], ['hint' => ['foo' => 1]]]],
14381438
fn (Builder $builder) => $builder->hint(['foo' => 1]),
14391439
];
1440+
1441+
yield 'timeout' => [
1442+
['find' => [[], ['maxTimeMS' => 2346]]],
1443+
fn (Builder $builder) => $builder->timeout(2.3456),
1444+
];
14401445
}
14411446

14421447
#[DataProvider('provideExceptions')]

0 commit comments

Comments
 (0)