Skip to content

Commit 8b1efe5

Browse files
committed
better performance for exists() method of Query class
#290
1 parent 22602c1 commit 8b1efe5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Query.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,24 @@ public function exists($db = null)
495495
if (!empty($this->emulateExecution)) {
496496
return false;
497497
}
498+
499+
#better performance
500+
#save last options
501+
$tmpOrderBy = $this->orderBy;
502+
$tmpLimit = $this->limit;
503+
$tmpOffset = $this->offset;
504+
$tmpSelect = $this->select;
505+
$this->orderBy = [];
506+
$this->limit = 1;
507+
$this->offset = null;
508+
$this->select = ['_id'];
498509
$cursor = $this->buildCursor($db);
510+
#return last options
511+
$this->orderBy = $tmpOrderBy;
512+
$this->limit = $tmpLimit;
513+
$this->offset = $tmpOffset;
514+
$this->select = $tmpSelect;
515+
499516
foreach ($cursor as $row) {
500517
return true;
501518
}

0 commit comments

Comments
 (0)