-
Notifications
You must be signed in to change notification settings - Fork 66
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
DOC Document manipulating eager loading queries #456
DOC Document manipulating eager loading queries #456
Conversation
79359bc
to
75fe8ee
Compare
5be588a
to
c17b502
Compare
]); | ||
``` | ||
|
||
The list passed into your callback represents the query for that relation on *all* of the records you're fetching. For example, above the `$list` variable is a `DataList` that will fetch all `Player` records in the `Players` relation for all `Team` records (so long as they match the filter applied in the callback). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"above the $list
variable" sounds really weird, should this be something like "before the $list DataList is created another DataList containing ... Players ..." ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapped to the `$list` variable above
. All this part is saying is that the $list
variable in the example is a DataList
, and what that list contains.
use SilverStripe\ORM\DataList; | ||
|
||
$teams = Team::get()->eagerLoad([ | ||
// Remove the callback that was previously defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously defined where? In the different example above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously defined anywhere at any time before this. Yes in the example above, but also in general, if there was previously a callback defined, setting this to null here will remove it.
en/08_Changelogs/5.2.0.md
Outdated
- HasMany - ~29% faster (0.1080s vs 0.7358s) | ||
- ManyMany - ~21% faster (0.1264s vs 0.9002s) | ||
- ManyManyThrough - ~21% faster (0.2511s vs 1.0719s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #458 (review) you need to "invert" these numbers
e.g. 0.2511s vs 1.0719s is ~400% faster, rather than 21%
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, but if you just feed me the calculation you want me to use I'll use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1.0719 / 0.2511) * 100 = ~427% faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ended up with (OLD / NEW * 100) - 100
as the calculation.
The rationale is: If old is 300 and new is 200, the new one is 50% faster than the old one.
I'll open a PR to update the 5.1 changelog as well. Double checked - the 5.1 changelog already uses the updated calculation.
c17b502
to
abf6e22
Compare
> [!CAUTION] | ||
> Filtering an `EagerLoadedlist` is significantly (up to 85%) slower than performing that manipulation on the eager loading query. | ||
> | ||
> See [manipulating eagerloading queries](#manipulating-eager-loading-queries). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this here as an early warning about this, for people who don't read the whole docs (i.e. most everyone).
It is intentionally duplicating a warning in that section.
use SilverStripe\ORM\DataList; | ||
|
||
$teams = Team::get()->eagerLoad([ | ||
// Remove the callback that was previously defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Remove the callback that was previously defined | |
// Remove any callback that was previously defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's not any callback, it's the callback for this relation chain. I'll try to make that clearer.
Also can you please try to keep changes like this which are related to discussions inside the threads which have the discussion? i.e. this has context in #456 (comment) which it's now decoupled from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
en/08_Changelogs/5.2.0.md
Outdated
- HasMany - ~29% faster (0.1080s vs 0.7358s) | ||
- ManyMany - ~21% faster (0.1264s vs 0.9002s) | ||
- ManyManyThrough - ~21% faster (0.2511s vs 1.0719s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1.0719 / 0.2511) * 100 = ~427% faster
abf6e22
to
f035344
Compare
f035344
to
c1b06fb
Compare
@@ -784,6 +784,11 @@ The N + 1 query problem can be alleviated using eager loading which in this exam | |||
$teams = Team::get()->eagerLoad('Players'); | |||
``` | |||
|
|||
> [!CAUTION] | |||
> Manipulating the eager loading query is significantly (up to ~600%) faster than Filtering an `EagerLoadedlist` after the query has been made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This percentage is based on the middle test in the issue - i.e. used to be 0.9002s, now 0.1264s. Rounded to the nearest 100
Description
Documents silverstripe/silverstripe-framework#11140
Issues
Pull request checklist