We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a collection with 500k records try to use $model = Model::find()->one();
get the model
Fatal error Out of memory
Reading Query.php i found that when we enter in this method
Query.php
protected function fetchRowsInternal($cursor, $all) { $result = []; if ($all) { foreach ($cursor as $row) { $result[] = $row; } } else { if ($row = current($cursor->toArray())) { $result = $row; } else { $result = false; } } return $result; }
in this moment $cursor is not limited with (limit = 1) and the cursor try to fetch the full collection generating an out of memory
Proposal Solution is add limit = 1 when we try to get one
limit = 1
public function one($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); return $this->fetchRows($cursor, false); }
after the change should looks like this
public function one($db = null) { if (!empty($this->emulateExecution)) { return false; } if (!isset($this->limit)) { $this->limit = 1; } $cursor = $this->buildCursor($db); return $this->fetchRows($cursor, false); }
The text was updated successfully, but these errors were encountered:
Related to #290
Sorry, something went wrong.
No branches or pull requests
What steps will reproduce the problem?
Create a collection with 500k records
try to use
$model = Model::find()->one();
What's expected?
get the model
What do you get instead?
Fatal error Out of memory
Additional info
Reading
Query.php
i found that when we enter in this methodin this moment $cursor is not limited with (limit = 1) and the cursor try to fetch the full collection generating an out of memory
Proposal Solution is add
limit = 1
when we try to get oneafter the change should looks like this
The text was updated successfully, but these errors were encountered: