Преглед изворни кода

Optimisation nombre requêtes

packProduct
Guillaume пре 2 година
родитељ
комит
e41a2e3923
9 измењених фајлова са 110 додато и 37 уклоњено
  1. +20
    -3
      Builder/Order/OrderShopBuilder.php
  2. +2
    -1
      Controller/ControllerTrait.php
  3. +3
    -0
      Repository/Product/ProductCategoryRepositoryQuery.php
  4. +21
    -7
      Repository/Product/ProductFamilyRepositoryQuery.php
  5. +6
    -6
      Repository/Product/ProductFamilyStore.php
  6. +2
    -2
      Repository/Product/ProductRepositoryQuery.php
  7. +40
    -7
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  8. +14
    -10
      Resolver/SectionResolver.php
  9. +2
    -1
      Twig/StoreTwigExtension.php

+ 20
- 3
Builder/Order/OrderShopBuilder.php Прегледај датотеку

@@ -50,6 +50,9 @@ use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

class OrderShopBuilder
{
@@ -128,11 +131,22 @@ class OrderShopBuilder
return $orderShop;
}


protected array $cacheCartCurrentBySection = [];

public function createIfNotExist(
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null
VisitorInterface $visitor = null,
bool $cache = false
): OrderShopInterface {

// cache
$cacheIdCartCurrent = 'cart_current_'.$section->getId();
if($cache && isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])) {
return $this->cacheCartCurrentBySection[$cacheIdCartCurrent];
}

$this->orderShopStore->setSection($section);

$cartUser = $this->orderShopStore->getOneCartCurrent($user);
@@ -148,10 +162,13 @@ class OrderShopBuilder
$cart = $this->create($section, $user, $visitor);
}

// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ?
$this->entityManager->refresh($cart);
// cache
$this->cacheCartCurrentBySection[$cacheIdCartCurrent] = $cart;

return $cart;

// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ?
//$this->entityManager->refresh($cart);
}

public function setOrderStatus(

+ 2
- 1
Controller/ControllerTrait.php Прегледај датотеку

@@ -157,7 +157,8 @@ trait ControllerTrait
return $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
$this->getSectionCurrent(),
$this->getUserCurrent(),
$this->getVisitorCurrent()
$this->getVisitorCurrent(),
true
);
}


+ 3
- 0
Repository/Product/ProductCategoryRepositoryQuery.php Прегледај датотеку

@@ -29,6 +29,9 @@ class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery

return $this;
}



public function hasProductFamilyOnline(): self
{
$this->joinProductFamilies();

+ 21
- 7
Repository/Product/ProductFamilyRepositoryQuery.php Прегледај датотеку

@@ -11,11 +11,10 @@ use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
{
//use SectionRepositoryQueryTrait;

protected bool $isJoinProductCategories = false;
protected bool $isJoinProductFamilySectionProperties = false;
protected bool $isJoinProducts = false;
protected bool $isJoinQualityLabels = false;

public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
{
@@ -35,6 +34,19 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

public function joinQualityLabels(bool $addSelect = true): self
{
if (!$this->isJoinQualityLabels) {
$this->isJoinQualityLabels = true;

$this->leftJoin('.qualityLabels', 'pfql');
if ($addSelect) {
$this->addSelect('pfql');
}
}
return $this;
}

public function filterBySection(SectionInterface $section,bool $addSelectProductFamilySectionProperties = true)
{
$this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
@@ -104,14 +116,15 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
return $this->andWhereEqual('supplier', $supplier);
}

public function joinProductCategories(): self
public function joinProductCategories(bool $addSelect = false): self
{
if (!$this->isJoinProductCategories) {
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'cat');
//$query->addSelect('cat') ; ???
->leftJoin('.productCategories', 'cat')
->addSelect('cat')
;
}
return $this;
}
@@ -129,8 +142,9 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProducts = true;

return $this
->innerJoin('.products', 'pfp');
// $query->addSelect('pfp') ; ?????
->innerJoin('.products', 'pfp')
->addSelect('pfp')
;
}
return $this;
}

+ 6
- 6
Repository/Product/ProductFamilyStore.php Прегледај датотеку

@@ -34,13 +34,9 @@ class ProductFamilyStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
if($this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}
$this->addFilterBySectionOptionnal($query);
$this->addFilterByMerchantViaSectionOptionnal($query);

return $query;
}
@@ -49,6 +45,8 @@ class ProductFamilyStore extends AbstractStore
{
$query->joinProductCategories();
$query->joinProducts();
$query->joinQualityLabels();

return $query;
}

@@ -252,7 +250,9 @@ class ProductFamilyStore extends AbstractStore

if (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) {
if ($organizeByParentCategory) {

$productCategories = $productFamily->getProductCategories();

if ($productCategories && count($productCategories) > 0) {
$parentCategory = $productCategories[0]->getParentCategory();
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {

+ 2
- 2
Repository/Product/ProductRepositoryQuery.php Прегледај датотеку

@@ -29,8 +29,8 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamily = true;

return $this
->innerJoin('.productFamily', 'pf');
//$qb->addSelect('pf'); ???
->innerJoin('.productFamily', 'pf')
->addSelect('pf');
}
return $this;
}

+ 40
- 7
Repository/Reduction/ReductionCatalogRepositoryQuery.php Прегледај датотеку

@@ -14,6 +14,9 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
protected bool $isJoinProductFamilies = false;
protected bool $isJoinProductFamily = false;
protected bool $isJoinProductCategories = false;
protected bool $isJoinUsers = false;
protected bool $isJoinGroupUsers = false;

use SectionRepositoryQueryTrait;

public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
@@ -21,14 +24,38 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
parent::__construct($repository, 'r', $paginator);
}

public function joinUsers()
{
if (!$this->isJoinUsers) {
$this->isJoinUsers = true;

return $this
->leftJoin('.users', 'pf_users')
->addSelect('pf_users') ;
}
return $this;
}

public function joinGroupUsers()
{
if (!$this->isJoinGroupUsers) {
$this->isJoinGroupUsers = true;

return $this
->leftJoin('.groupUsers', 'pf_groupusers')
->addSelect('pf_groupusers') ;
}
return $this;
}

public function joinProductFamilies()
{
if (!$this->isJoinProductFamilies) {
$this->isJoinProductFamilies = true;

return $this
->leftJoin('.productFamilies', 'pfs');
//->addSelect('pfs') ;
->leftJoin('.productFamilies', 'pfs')
->addSelect('pfs') ;
}
return $this;
}
@@ -39,8 +66,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamily = true;

return $this
->leftJoin('.productFamily', 'pf');
//->addSelect('pf') ;
->leftJoin('.productFamily', 'pf')
->addSelect('pf') ;
}
return $this;
}
@@ -51,13 +78,12 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'pcs');
//->addSelect('pcs') ;
->leftJoin('.productCategories', 'pcs')
->addSelect('pcs') ;
}
return $this;
}


public function filterProductFamily(ProductFamilyInterface $productFamily)
{
return $this
@@ -74,6 +100,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

public function filterConditionUser(UserInterface $user = null)
{
$this->joinUsers();

if ($user) {
return $this
->andWhere(':user MEMBER OF .users OR .users is empty')
@@ -86,6 +114,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

public function filterConditionGroupUser(UserInterface $user = null)
{
$this->joinGroupUsers();

if ($user) {
return $this
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
@@ -100,6 +130,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
{
$this->joinProductFamilies();
$this->joinProductFamily();

return $this
->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamilies', $productFamilies);
@@ -109,6 +140,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
{
$this->joinProductFamilies();
$this->joinProductFamily();

return $this
->andWhere(':productFamily MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamily', $productFamily);
@@ -117,6 +149,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
public function filterConditionProductCategories(array $productCategories)
{
$this->joinProductCategories();

return $this
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);

+ 14
- 10
Resolver/SectionResolver.php Прегледај датотеку

@@ -68,18 +68,22 @@ class SectionResolver
}
} // front
else {
$merchantCurrent = $this->merchantResolver->getCurrent();
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent);
$sectionCurrent = null;
$sectionDefault = $sectionStore->getOneDefault();

if (isset($requestAttributesArray['section'])) {
$sectionCurrent = $sectionStore
->setMerchant($merchantCurrent)
->getOneBySlug($requestAttributesArray['section']);
if($this->section === null) {
$merchantCurrent = $this->merchantResolver->getCurrent();
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent);
$sectionCurrent = null;
$sectionDefault = $sectionStore->getOneDefault();

if (isset($requestAttributesArray['section'])) {
$sectionCurrent = $sectionStore
->setMerchant($merchantCurrent)
->getOneBySlug($requestAttributesArray['section']);
}

$this->section = $sectionCurrent ?: $sectionDefault;
}

return $sectionCurrent ?: $sectionDefault;
return $this->section;
}
}


+ 2
- 1
Twig/StoreTwigExtension.php Прегледај датотеку

@@ -120,7 +120,8 @@ class StoreTwigExtension extends AbstractExtension
return $this->orderShopBuilder->createIfNotExist(
$this->sectionResolver->getCurrent(),
$this->security->getUser(),
$this->visitorResolver->getCurrent()
$this->visitorResolver->getCurrent(),
true
);
}


Loading…
Откажи
Сачувај