Skip to content

Commit

Permalink
Merge pull request #1843 from dpfaffenbauer/issue/cache
Browse files Browse the repository at this point in the history
[Cache] optimize Pimcore cache with doctrine entities
  • Loading branch information
dpfaffenbauer authored Jan 21, 2022
2 parents 488a322 + c8f7e3f commit 2c51349
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 52 deletions.
14 changes: 13 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CoreShop\Bundle\CoreBundle\Form\Type\Product\ProductStoreValuesType;
use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait;
use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger;
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Core\Model\ProductStoreValuesInterface;
use CoreShop\Component\Core\Model\StoreInterface;
Expand All @@ -39,7 +40,8 @@ class StoreValues extends Model\DataObject\ClassDefinition\Data implements
Model\DataObject\ClassDefinition\Data\CustomResourcePersistingInterface,
Model\DataObject\ClassDefinition\Data\CustomVersionMarshalInterface,
Model\DataObject\ClassDefinition\Data\CustomRecyclingMarshalInterface,
Model\DataObject\ClassDefinition\Data\CustomDataCopyInterface
Model\DataObject\ClassDefinition\Data\CustomDataCopyInterface,
CacheMarshallerInterface
{
use TempEntityManagerTrait;

Expand Down Expand Up @@ -550,6 +552,16 @@ public function unmarshalRecycleData($object, $data)
return $this->unmarshalVersion($object, $data);
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}

public function delete($object, $params = [])
{
if (!$object instanceof ProductInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CoreShop\Bundle\ProductBundle\Form\Type\ProductSpecificPriceRuleType;
use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait;
use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger;
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Product\Model\ProductInterface;
use CoreShop\Component\Product\Model\ProductSpecificPriceRuleInterface;
use CoreShop\Component\Product\Repository\ProductSpecificPriceRuleRepositoryInterface;
Expand All @@ -36,7 +37,8 @@ class ProductSpecificPriceRules extends Data implements
Data\CustomResourcePersistingInterface,
Data\CustomVersionMarshalInterface,
Data\CustomRecyclingMarshalInterface,
Data\CustomDataCopyInterface
Data\CustomDataCopyInterface,
CacheMarshallerInterface
{
use TempEntityManagerTrait;

Expand Down Expand Up @@ -249,6 +251,16 @@ public function unmarshalRecycleData($object, $data)
return $this->unmarshalVersion($object, $data);
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}

/**
* @param array $data
* @param null $object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace CoreShop\Bundle\ProductBundle\CoreExtension;

use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Product\Model\ProductInterface;
use CoreShop\Component\Product\Model\ProductUnitDefinitionInterface;
use CoreShop\Component\Product\Model\ProductUnitDefinitionsInterface;
Expand All @@ -28,7 +29,8 @@
class ProductUnitDefinition extends Data implements
Data\ResourcePersistenceAwareInterface,
Data\QueryResourcePersistenceAwareInterface,
Data\CustomVersionMarshalInterface
Data\CustomVersionMarshalInterface,
CacheMarshallerInterface
{
/**
* Static type of this element.
Expand Down Expand Up @@ -198,6 +200,16 @@ public function unmarshalRecycleData($object, $data)
return $this->unmarshalVersion($object, $data);
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}

public function getDataFromEditmode($data, $object = null, $params = [])
{
return $this->getDataFromResource($data, $object, $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CoreShop\Bundle\ProductBundle\Form\Type\Unit\ProductUnitDefinitionsType;
use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait;
use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger;
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Product\Model\ProductInterface;
use CoreShop\Component\Product\Model\ProductUnitDefinitionInterface;
use CoreShop\Component\Product\Model\ProductUnitDefinitionsInterface;
Expand All @@ -39,7 +40,8 @@ class ProductUnitDefinitions extends Data implements
Data\CustomResourcePersistingInterface,
Data\CustomVersionMarshalInterface,
Data\CustomRecyclingMarshalInterface,
Data\CustomDataCopyInterface
Data\CustomDataCopyInterface,
CacheMarshallerInterface
{
use TempEntityManagerTrait;

Expand Down Expand Up @@ -283,6 +285,16 @@ public function unmarshalRecycleData($object, $data)
return $this->unmarshalVersion($object, $data);
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}

public function getDataFromResource($data, $object = null, $params = [])
{
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CoreShop\Bundle\ProductQuantityPriceRulesBundle\Form\Type\ProductQuantityPriceRuleType;
use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait;
use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger;
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\ProductQuantityPriceRules\Events;
use CoreShop\Component\ProductQuantityPriceRules\Model\ProductQuantityPriceRuleInterface;
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangeInterface;
Expand All @@ -40,7 +41,8 @@ class ProductQuantityPriceRules extends Data implements
Data\CustomResourcePersistingInterface,
Data\CustomVersionMarshalInterface,
Data\CustomRecyclingMarshalInterface,
Data\CustomDataCopyInterface
Data\CustomDataCopyInterface,
CacheMarshallerInterface
{
use TempEntityManagerTrait;

Expand Down Expand Up @@ -250,6 +252,16 @@ public function unmarshalRecycleData($object, $data)
return $this->unmarshalVersion($object, $data);
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}

/**
* @param mixed $data
* @param null $object
Expand Down
16 changes: 15 additions & 1 deletion src/CoreShop/Bundle/ResourceBundle/CoreExtension/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@

namespace CoreShop\Bundle\ResourceBundle\CoreExtension;

use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Resource\Model\ResourceInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Pimcore\Model;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;

/**
* @psalm-suppress InvalidReturnType, InvalidReturnStatement
*/
abstract class Select extends Data implements
Data\ResourcePersistenceAwareInterface,
Data\QueryResourcePersistenceAwareInterface,
Data\CustomRecyclingMarshalInterface
Data\CustomRecyclingMarshalInterface,
Data\CustomVersionMarshalInterface,
CacheMarshallerInterface
{
use Model\DataObject\Traits\SimpleComparisonTrait;

Expand Down Expand Up @@ -230,4 +234,14 @@ public function setAllowEmpty($allowEmpty)
{
$this->allowEmpty = $allowEmpty;
}

public function marshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->marshalVersion($concrete, $data);
}

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed
{
return $this->unmarshalVersion($concrete, $data);
}
}
2 changes: 2 additions & 0 deletions src/CoreShop/Bundle/ResourceBundle/CoreShopResourceBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\InstalledVersions;
use CoreShop\Bundle\CoreBundle\Application\Version;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler\PimcoreCachePass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterInstallersPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterPimcoreRepositoriesPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterPimcoreResourcesPass;
Expand Down Expand Up @@ -54,6 +55,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new StackRepositoryPass());
$container->addCompilerPass(new RegisterPimcoreRepositoriesPass());
$container->addCompilerPass(new ValidatorAutoMappingFixPass());
$container->addCompilerPass(new PimcoreCachePass());
}

public static function registerDependentBundles(BundleCollection $collection): void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

declare(strict_types=1);

namespace CoreShop\Bundle\ResourceBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\ResourceBundle\Pimcore\CacheResourceMarshaller;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class PimcoreCachePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$container->getDefinition('pimcore.cache.adapter.pdo')->setArgument(4, []);
$container->getDefinition('pimcore.cache.adapter.pdo')->setArgument(5, new Reference(CacheResourceMarshaller::class));

$container->getDefinition('pimcore.cache.adapter.redis_tag_aware')->setArgument(4, new Reference(CacheResourceMarshaller::class));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

declare(strict_types=1);

namespace CoreShop\Bundle\ResourceBundle\Pimcore;

use Pimcore\Model\DataObject\Concrete;

interface CacheMarshallerInterface
{
public function marshalForCache(Concrete $concrete, mixed $data): mixed;

public function unmarshalForCache(Concrete $concrete, mixed $data): mixed;
}
Loading

0 comments on commit 2c51349

Please sign in to comment.