-
Notifications
You must be signed in to change notification settings - Fork 46
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
Fixed missing env options in admin context #402
Conversation
I can't unterstand the rector error 😳 |
We should preload this relations, otherwise this will strongly increase db requests and memory usage. |
To avoid repeating |
- Reduced database access
The NavItem of a NavItemType doesn't change on object lifetime. Is this assumption correct? |
- Added env options in block iteration in `getPlaceholder()` - Added optional argument `$envOptions` for `getBlockItem()` - Ternary operator for env option `'equalIndex'`
Thanks for all the work, sorry for late and bad reply. There is no need for private variable in a yii2 relation if you define $this->hasOne() relation in a method:
then you have to use $object->navItem, this will establish the relation and its already stored, so a second call to $object->navItem will not result in a second query. what i meant is that this above relation should be preloaded using ->with(['navItem]) at the point where all blocks are iterated, maybe its already the case. |
if (!$blockItem->block) { | ||
return false; | ||
} | ||
|
||
$blockObject = $blockItem->block->getObject($blockItem->id, 'admin', $navItemPage); | ||
$blockObject = $blockItem->block->getObject($blockItem->id, 'admin', $navItemPage->getNavItem()); |
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 won't pass the relation, this will pass an active query instance, not an active record. So if you like to pass the nav item object, then you have to use navItemPage->navItem
. There is no unit tests for this, then this would fail here :-)
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'm confused because of two reasons.
The guide https://luya.io/guide/cms/blocks.html#env-context-information says
pageObject: Returns the
luya\cms\models\NavItem
object where you can runluya\cms\models\NavItem->getNav()
to retrieve theluya\cms\models\Nav
object.
And for the frontend context getNavItem()
is already used in NavItemPage::renderPlaceholderRecursive()
:
luya-module-cms/src/models/NavItemPage.php
Line 244 in a05aac2
$blockObject = Block::createObject($placeholder['class'], $placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem()); |
The pageObject should anyway be the same in frontend and admin context, so we should use $navItemPage->navItem
resp. $this->navItem
.
in general, i think we need a unit tests for this huge changeset. |
Of course!
I should have read https://www.yiiframework.com/wiki/834/relational-query-lazy-loading-and-eager-loading-in-yii-2-0#eager-loading before. But at the point in question ( Would it be sufficient to store the ActiceRecord in a variable before the block iteration? luya-module-cms/src/models/NavItemPage.php Lines 436 to 437 in a05aac2
|
i have quickly created a PR with just the required parts for your code, thanks! can you check it quickly maybe? |
Thank you.
See #403 (review). |
This reverts commit 73c5072.
lets continue with my PR and we take care of each problem by seperate pr. agree? 👍 |
Agreed! |
Thank again. The PR with the env options have been merged into the master. Problem with page object still exists. |
What are you changing/introducing
'pageObject'
is available'index'
,'itemsCount'
,'isFirst'
,'isLast'
,'isPrevEqual'
,'isNextEqual'
and'equalIndex'
for admin context in the block iteration ingetPlaceholder()
analog torenderPlaceholderRecursive()
NavItemPage::getBlockItem()
What is the reason for changing/introducing
QA