Skip to content
New issue

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

Needs to refactor Query::each() #821

Open
Tigrov opened this issue Apr 16, 2024 · 0 comments
Open

Needs to refactor Query::each() #821

Tigrov opened this issue Apr 16, 2024 · 0 comments
Assignees

Comments

@Tigrov
Copy link
Member

Tigrov commented Apr 16, 2024

Query::each() returns data reader to get data row by row.

foreach ($query->each() as $row) {}

Current realization of the data reader reads batch of rows then read each row from the rows.

if ($this->batch === null || !$this->each || (next($this->batch) === false)) {
$this->batch = $this->fetchData();
reset($this->batch);
}
if ($this->each) {
$this->value = current($this->batch);
if ($this->query->getIndexBy() !== null) {
$this->key = key($this->batch);
} elseif (key($this->batch) !== null) {
$this->key = $this->key === null ? 0 : (int) $this->key + 1;
} else {
$this->key = null;
}
} else {

If read the result of query row by row (instead of batch of rows), this will be more efficient and will use less memory.

@Tigrov Tigrov self-assigned this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant