This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not track multiple hints/sorts in Cursor
Successive calls to MongoCursor::hint() or sort() will overwrite the previous value, so there is no reason to store multiple values in the Doctrine class. ODM does seem to depend on the hints property to track UnitOfWork hints (entirely different than MongoDB index usage hints), but that should be changed upstream.
- Loading branch information
Showing
1 changed file
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,15 +44,15 @@ class Cursor implements Iterator | |
protected $numRetries; | ||
protected $query = array(); | ||
protected $fields = array(); | ||
protected $hints = array(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jmikola
Author
Member
|
||
protected $hint; | ||
protected $immortal; | ||
protected $options = array(); | ||
protected $batchSize; | ||
protected $limit; | ||
protected $skip; | ||
protected $slaveOkay; | ||
protected $snapshot; | ||
protected $sorts = array(); | ||
protected $sort; | ||
protected $tailable; | ||
protected $timeout; | ||
|
||
|
@@ -99,8 +99,8 @@ public function getFields() | |
public function recreate() | ||
{ | ||
$this->mongoCursor = $this->collection->getMongoCollection()->find($this->query, $this->fields); | ||
foreach ($this->hints as $hint) { | ||
$this->mongoCursor->hint($hint); | ||
if ($this->hint !== null) { | ||
$this->mongoCursor->hint($this->hint); | ||
} | ||
if ($this->immortal !== null) { | ||
$this->mongoCursor->immortal($this->immortal); | ||
|
@@ -123,8 +123,8 @@ public function recreate() | |
if ($this->snapshot) { | ||
$this->mongoCursor->snapshot(); | ||
} | ||
foreach ($this->sorts as $sort) { | ||
$this->mongoCursor->sort($sort); | ||
if ($this->sort !== null) { | ||
$this->mongoCursor->sort($this->sort); | ||
} | ||
if ($this->tailable !== null) { | ||
$this->mongoCursor->tailable($this->tailable); | ||
|
@@ -204,7 +204,7 @@ public function hasNext() | |
|
||
public function hint(array $keyPattern) | ||
{ | ||
$this->hints[] = $keyPattern; | ||
$this->hint = $keyPattern; | ||
$this->mongoCursor->hint($keyPattern); | ||
return $this; | ||
} | ||
|
@@ -339,7 +339,7 @@ public function sort($fields) | |
} | ||
$fields[$fieldName] = (integer) $order; | ||
} | ||
$this->sorts[] = $fields; | ||
$this->sort = $fields; | ||
$this->mongoCursor->sort($fields); | ||
return $this; | ||
} | ||
|
After apply this change I obtain the next error: