Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add tests and functionality for model::cursor() method. #513

mikebronner started this conversation in Ideas
Discussion options

You must be logged in to vote

Replies: 2 comments

Comment options

@mikebronner I have had a look at this and it seems that it completely skips caching as it uses Query\Builder under the hood to execute the query for each record.

Eloquent\Builder

public function cursor()
{
 // Swaps to using QueryBuilder ⬇️ then ⬇️ creates `LazyCollection` 
 return $this->applyScopes()->query->cursor()->map(function ($record) {
 return $this->newModelInstance()->newFromBuilder($record);
 });
}

Query\Builder

 public function cursor()
 {
 if (is_null($this->columns)) {
 $this->columns = ['*'];
 }
 return new LazyCollection(function () {
 yield from $this->connection->cursor(
 $this->toSql(), $this->getBindings(), ! $this->useWritePdo
 );
 });
 }

So you could say use of cursor is not cached. The only other option would be write your own implementation of the cursor method

In my opinion it is probably not necessary to cache the cursor function since it is generally used for large data quantities. So if you cached each if the individual record queries it could put quite some load on the cache instance.

You must be logged in to vote
0 replies
Comment options

@dmason30 Good analysis! I add this to the documentation that this method is not cached.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Converted from issue

This discussion was converted from issue #310 on March 05, 2025 14:02.

AltStyle によって変換されたページ (->オリジナル) /