Skip to content

Commit

Permalink
better performance for exists() method of Query class
Browse files Browse the repository at this point in the history
  • Loading branch information
ziaratban committed Dec 27, 2019
1 parent 22602c1 commit 8b1efe5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,24 @@ public function exists($db = null)
if (!empty($this->emulateExecution)) {
return false;
}

#better performance
#save last options
$tmpOrderBy = $this->orderBy;
$tmpLimit = $this->limit;
$tmpOffset = $this->offset;
$tmpSelect = $this->select;
$this->orderBy = [];
$this->limit = 1;
$this->offset = null;
$this->select = ['_id'];
$cursor = $this->buildCursor($db);
#return last options
$this->orderBy = $tmpOrderBy;
$this->limit = $tmpLimit;
$this->offset = $tmpOffset;
$this->select = $tmpSelect;

foreach ($cursor as $row) {
return true;
}
Expand Down

0 comments on commit 8b1efe5

Please sign in to comment.