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

[Data Object] Relations should be always lazy loaded, remove config o… #5775

Merged
merged 12 commits into from Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -82,27 +82,6 @@ pimcore.object.classes.data.advancedManyToManyObjectRelation = Class.create(pimc
disabled: this.isInCustomLayoutEditor(),
minValue: 0
},
{
xtype: "checkbox",
fieldLabel: t("lazy_loading"),
name: "lazyLoading",
checked: this.datax.lazyLoading && !this.lazyLoadingNotPossible(),
disabled: this.isInCustomLayoutEditor() || this.lazyLoadingNotPossible()
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_description'),
cls: "pimcore_extra_label_bottom",
style: "padding-bottom:0;"
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_warning_block'),
cls: "pimcore_extra_label_bottom",
style: "color:red; font-weight: bold;"
},
{
xtype: 'textfield',
width: 600,
Expand Down
Expand Up @@ -175,27 +175,6 @@ pimcore.object.classes.data.advancedManyToManyRelation = Class.create(pimcore.ob
disabled: this.isInCustomLayoutEditor(),
minValue: 0
},
{
xtype: "checkbox",
fieldLabel: t("lazy_loading"),
name: "lazyLoading",
checked: this.datax.lazyLoading && !this.lazyLoadingNotPossible(),
disabled: this.isInCustomLayoutEditor() || this.lazyLoadingNotPossible()
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_description'),
cls: "pimcore_extra_label_bottom",
style: "padding-bottom:0;"
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_warning_block'),
cls: "pimcore_extra_label_bottom",
style: "color:red; font-weight: bold;"
},
{
xtype: 'textfield',
width: 600,
Expand Down
Expand Up @@ -85,27 +85,6 @@ pimcore.object.classes.data.manyToManyObjectRelation = Class.create(pimcore.obje
disabled: this.isInCustomLayoutEditor(),
minValue: 0
},
{
xtype: "checkbox",
fieldLabel: t("lazy_loading"),
name: "lazyLoading",
checked: this.datax.lazyLoading && !this.lazyLoadingNotPossible(),
disabled: this.isInCustomLayoutEditor() || this.lazyLoadingNotPossible()
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_description'),
cls: "pimcore_extra_label_bottom",
style: "padding-bottom:0;"
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_warning_block'),
cls: "pimcore_extra_label_bottom",
style: "color:red; font-weight: bold;"
},
{
xtype: 'textfield',
width: 600,
Expand Down
Expand Up @@ -179,28 +179,6 @@ pimcore.object.classes.data.manyToManyRelation = Class.create(pimcore.object.cla
value: this.datax.maxItems,
minValue: 0
},
{
xtype: "checkbox",
fieldLabel: t("lazy_loading"),
name: "lazyLoading",
checked: this.datax.lazyLoading && !this.lazyLoadingNotPossible(),
disabled: this.isInCustomLayoutEditor() || this.lazyLoadingNotPossible()

},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_description'),
cls: "pimcore_extra_label_bottom",
style: "padding-bottom:0;"
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_warning_block'),
cls: "pimcore_extra_label_bottom",
style: "color:red; font-weight: bold; padding-bottom:0;"
},
{
xtype: 'textfield',
width: 600,
Expand Down
Expand Up @@ -163,27 +163,6 @@ pimcore.object.classes.data.manyToOneRelation = Class.create(pimcore.object.clas
name: "width",
value: this.datax.width
} ,
{
xtype: "checkbox",
fieldLabel: t("lazy_loading"),
name: "lazyLoading",
disabled: this.isInCustomLayoutEditor() || this.lazyLoadingNotPossible(),
checked: this.datax.lazyLoading && !this.lazyLoadingNotPossible()
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_description'),
cls: "pimcore_extra_label_bottom",
style: "padding-bottom:0;"
},
{
xtype: "displayfield",
hideLabel: true,
value: t('lazy_loading_warning_block'),
cls: "pimcore_extra_label_bottom",
style: "color:red; font-weight: bold; padding-bottom:0;"
},
{
xtype: 'textfield',
width: 600,
Expand Down
2 changes: 0 additions & 2 deletions bundles/CoreBundle/Resources/translations/en.extended.json
Expand Up @@ -92,7 +92,6 @@
"composite": "Composite",
"origin": "Origin",
"high_resolution": "High Resolution",
"lazy_loading_warning_block": "WARNING: Lazy Loading is NOT possible within Blocks",
"pass_through_params": "Pass Through Params",
"redirects_type_entire_uri": "Entire URI",
"redirects_type_path_query": "Path and Query",
Expand Down Expand Up @@ -380,7 +379,6 @@
"user_apikey_description": "API key required for web service access by this user",
"apikey": "API Key",
"lazy_loading": "lazy loading",
"lazy_loading_description": "Lazy loading means that related objects are not loaded initially when the object is instantiated. When accessing the object programmatically, relations are only loaded when the according get method is called.",
"non_owner_description": "Non owner objects represent relations to an other object just in the same way as objects do. The difference is, that a non-owner object field is not the owner of the relation data, it is merely a view on data stored in other objects. Please choose the owner and field name where the data is originally stored.",
"allow_variants": "Allow variants",
"show_variants": "Show variants in tree",
Expand Down
Expand Up @@ -205,6 +205,9 @@ $object->setMetadata($references);


## Lazy Loading

> Note that from 6.5.0 on relations are always lazy loaded. The configuration option has been removed.

Whenever an object is loaded from database or cache, all these related objects are loaded with it. Especially with
Many-To-Many relations it is easy to produce a huge amount of relations, which makes the object or an object list slow
in loading.
Expand Down
Expand Up @@ -2,10 +2,13 @@


## 6.5.0
- Relations are always lazy-loaded from now on
see https://github.com/pimcore/pimcore/issues/5772
- Relation Types DB Caching Layer is always turned on now. Removed support for non-cached alternative.
All rows of the affected `object_relation_` table will be fetched in on go and cached together we with the object.
see https://github.com/pimcore/pimcore/issues/5427
- If you have custom lazy-loaded datatypes **not** extending `Pimcore\Model\DataObject\ClassDefinition\Data\Relations\AbstractRelations`, implement the `LazyLoadingSupportInterface`
- If you have custom lazy-loaded datatypes **not** extending `Pimcore\Model\DataObject\ClassDefinition\Data\Relations\AbstractRelations`,
implement the `Pimcore\Model\DataObject\ClassDefinition\Data\LazyLoadingSupportInterface`
The `method_exists('getLazyLoading')` calls will be removed in Pimcore 7.
- It is now possible to configure `php:memory_limit` for `web2print:pdf-creation` command with following configuration:
```yaml
Expand Down
5 changes: 4 additions & 1 deletion models/DataObject/ClassDefinition/Data/Block.php
Expand Up @@ -1183,7 +1183,10 @@ public function classSaved($class, $params = [])
foreach ($blockDefinitions as $field) {
if (($field instanceof LazyLoadingSupportInterface || method_exists($field, 'getLazyLoading'))
&& $field->getLazyLoading()) {
$field->setLazyLoading(false);
// Lazy loading inside blocks isn't supported
if (!$field instanceof Data\Relations\AbstractRelations) {
$field->setLazyLoading(false);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/ClassDefinition/Data/Localizedfields.php
Expand Up @@ -176,7 +176,7 @@ private function doGetDataForEditMode($data, $object, &$fieldData, &$metaData, $
$dataItems = $data->getInternalData(true);
foreach ($dataItems as $language => $values) {
foreach ($this->getFieldDefinitions() as $fd) {
if ($fd instanceof LazyLoadingSupportInterface && !DataObject\Concrete::isLazyLoadingDisabled() && $fd->getLazyLoading()) {
if ($fd instanceof LazyLoadingSupportInterface && $fd->getLazyLoading()) {
$lazyKey = $fd->getName() . DataObject\LazyLoadedFieldsInterface::LAZY_KEY_SEPARATOR . $language;
if (!$data->isLazyKeyLoaded($lazyKey)) {
$params['language'] = $language;
Expand Down
Expand Up @@ -32,11 +32,6 @@ abstract class AbstractRelations extends Data implements

const RELATION_ID_SEPARATOR = '$$';

/**
* @var bool
*/
public $lazyLoading;

/**
* Set of allowed classes
*
Expand Down Expand Up @@ -74,20 +69,9 @@ public function setClasses($classes)
*/
public function getLazyLoading()
dvesh3 marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->lazyLoading;
return true;
}

/**
* @param bool $lazyLoading
*
* @return $this
*/
public function setLazyLoading($lazyLoading)
dvesh3 marked this conversation as resolved.
Show resolved Hide resolved
{
$this->lazyLoading = $lazyLoading;

return $this;
}

/**
* @param $object
Expand Down Expand Up @@ -156,7 +140,7 @@ public function load($object, $params = [])
$relations = [];

if ($object instanceof DataObject\Concrete) {
if (!$this->getLazyLoading() || (array_key_exists('force', $params) && $params['force'])) {
if (array_key_exists('force', $params) && $params['force']) {
$relations = $object->retrieveRelationData(['fieldname' => $this->getName(), 'ownertype' => 'object']);
} else {
return null;
Expand Down Expand Up @@ -407,7 +391,7 @@ public function supportsDirtyDetection()
*/
public function loadLazyFieldcollectionField(DataObject\Fieldcollection\Data\AbstractData $item)
{
if ($this->getLazyLoading() && $item->getObject()) {
if ($item->getObject()) {
/** @var DataObject\Fieldcollection $container */
$container = $item->getObject()->getObjectVar($item->getFieldname());
if ($container) {
Expand All @@ -426,7 +410,7 @@ public function loadLazyFieldcollectionField(DataObject\Fieldcollection\Data\Abs
*/
public function loadLazyBrickField(DataObject\Objectbrick\Data\AbstractData $item)
{
if ($this->getLazyLoading() && $item->getObject()) {
if ($item->getObject()) {
/** @var DataObject\Objectbrick $container */
$container = $item->getObject()->getObjectVar($item->getFieldname());
if ($container) {
Expand Down
33 changes: 0 additions & 33 deletions models/DataObject/Concrete.php
Expand Up @@ -853,39 +853,6 @@ public function __clone()
parent::__clone();
}

/**
* @var bool
*/
protected static $disableLazyLoading = false;

/**
* @internal
* Disables lazy loading
*/
public static function disableLazyLoading()
{
self::$disableLazyLoading = true;
}

/**
* @internal
* Enables the lazy loading
*/
public static function enableLazyloading()
{
self::$disableLazyLoading = false;
}

/**
* @internal
*
* @return bool
*/
public static function isLazyLoadingDisabled()
{
return self::$disableLazyLoading;
}

/**
* @internal
*
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Fieldcollection/Dao.php
Expand Up @@ -79,7 +79,7 @@ public function load(DataObject\Concrete $object)
if ($fd instanceof CustomResourcePersistingInterface) {
$doLoad = true;
if ($fd instanceof LazyLoadingSupportInterface) {
if (!DataObject\Concrete::isLazyLoadingDisabled() && $fd->getLazyLoading()) {
if ($fd->getLazyLoading()) {
$doLoad = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Localizedfield.php
Expand Up @@ -416,7 +416,7 @@ public function getLocalizedValue($name, $language = null, $ignoreFallbackLangua
return $data;
}

if ($fieldDefinition instanceof LazyLoadingSupportInterface && !Concrete::isLazyLoadingDisabled() && $fieldDefinition->getLazyLoading()) {
if ($fieldDefinition instanceof LazyLoadingSupportInterface && $fieldDefinition->getLazyLoading()) {
$this->loadLazyField($fieldDefinition, $name, $language);
}

Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Localizedfield/Dao.php
Expand Up @@ -587,7 +587,7 @@ public function load($object, $params = [])
}
$params['context']['object'] = $object;

if ($fd instanceof LazyLoadingSupportInterface && !DataObject\Concrete::isLazyLoadingDisabled() && $fd->getLazyLoading()) {
if ($fd instanceof LazyLoadingSupportInterface && $fd->getLazyLoading()) {
$lazyKey = $fd->getName() . DataObject\LazyLoadedFieldsInterface::LAZY_KEY_SEPARATOR . $row['language'];
} else {
$value = $fd->load($this->model, $params);
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Objectbrick/Dao.php
Expand Up @@ -67,7 +67,7 @@ public function load(DataObject\Concrete $object, $params = [])
$doLoad = true;

if ($fd instanceof LazyLoadingSupportInterface) {
if (!DataObject\Concrete::isLazyLoadingDisabled() && $fd->getLazyLoading()) {
if ($fd->getLazyLoading()) {
$doLoad = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Objectbrick/Data/AbstractData.php
Expand Up @@ -256,7 +256,7 @@ protected function getLazyLoadedFieldNames(): array
$lazyLoadedFieldNames = [];
$fields = $this->getDefinition()->getFieldDefinitions(['suppressEnrichment' => true]);
foreach ($fields as $field) {
if (($field instanceof LazyLoadingSupportInterface || method_exists($field, 'getLazyLoading'))
if (($field instanceof LazyLoadingSupportInterface || method_exists($field, 'getLazyLoading'))
&& $field->getLazyLoading()) {
$lazyLoadedFieldNames[] = $field->getName();
}
Expand Down
@@ -0,0 +1,23 @@
<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @category Pimcore
* @package Element
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

namespace Pimcore\Model\DataObject\Traits;

trait FieldcollectionObjectbrickDefinitionTrait
weisswurstkanone marked this conversation as resolved.
Show resolved Hide resolved
{

}
6 changes: 0 additions & 6 deletions tests/_support/Helper/DataType/TestDataHelper.php
Expand Up @@ -1170,7 +1170,6 @@ public function fillBricks(Concrete $object, $field, $seed = 1)

$emptyObjects = TestHelper::createEmptyObjects('myBrickPrefix', true, 10);
$emptyLazyObjects = TestHelper::createEmptyObjects('myLazyBrickPrefix', true, 15);
$brick->setBrickRelation($emptyObjects);
$brick->setBrickLazyRelation($emptyLazyObjects);

/** @var DataObject\Unittest\Mybricks $objectbricks */
Expand Down Expand Up @@ -1199,9 +1198,6 @@ public function assertBricks(Concrete $object, $field, $seed = 1)

$this->assertEquals($expectedInputValue, $inputValue);

$fieldRelation = $value->getBrickRelation();
$this->assertEquals(10, count($fieldRelation), 'expected 10 items');

$fieldLazyRelation = $value->getBrickLazyRelation();
$this->assertEquals(15, count($fieldLazyRelation), 'expected 15 items');

Expand All @@ -1213,8 +1209,6 @@ public function assertBricks(Concrete $object, $field, $seed = 1)

/** @var DataObject\Fieldcollection\Data\Unittestfieldcollection $value */
$value = $value[0];
$fieldRelation = $value->getBrickRelation();
$this->assertEquals(10, count($fieldRelation), 'expected 10 items');

$fieldLazyRelation = $value->getBrickLazyRelation();
$this->assertEquals(15, count($fieldLazyRelation), 'expected 15 items');
Expand Down