Browse Source

SectionResolver : système de cache

packProduct
Guillaume 3 years ago
parent
commit
445c6b93c5
3 changed files with 24 additions and 5 deletions
  1. +4
    -1
      Builder/Order/OrderShopBuilder.php
  2. +3
    -4
      Repository/Order/OrderShopRepositoryQuery.php
  3. +17
    -0
      Resolver/SectionResolver.php

+ 4
- 1
Builder/Order/OrderShopBuilder.php View File



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

return $this->cacheCartCurrentBySection[$cacheIdCartCurrent]; return $this->cacheCartCurrentBySection[$cacheIdCartCurrent];
} }



+ 3
- 4
Repository/Order/OrderShopRepositoryQuery.php View File



public function filterByVisitor(VisitorInterface $visitor): self public function filterByVisitor(VisitorInterface $visitor): self
{ {
return $this
->andWhere('.visitor = :visitor')
->setParameter('visitor', $visitor);
return $this->andWhereEqual('visitor', $visitor);
} }


public function filterByAddress(AddressInterface $address): self public function filterByAddress(AddressInterface $address): self
if (!$this->isJoinOrderProduct) { if (!$this->isJoinOrderProduct) {
$this->isJoinOrderProduct = true; $this->isJoinOrderProduct = true;


$this->innerJoin('.orderProducts', 'orderProduct');
$this->leftJoin('.orderProducts', 'orderProduct');

if ($addSelect) { if ($addSelect) {
$this->addSelect('orderProduct'); $this->addSelect('orderProduct');
} }

+ 17
- 0
Resolver/SectionResolver.php View File

protected bool $isCachedSection = false; protected bool $isCachedSection = false;
protected ?SectionInterface $section = null; protected ?SectionInterface $section = null;


// cache front
protected ?SectionInterface $cacheSectionCurrent = null;
protected ?SectionInterface $cacheSectionVisited = null;
protected ?SectionInterface $cacheSectionDefault = null;

protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected Security $security; protected Security $security;
protected MerchantResolver $merchantResolver; protected MerchantResolver $merchantResolver;
} }
} // front } // front
else { else {

if ($this->cacheSectionCurrent) {
return $this->cacheSectionCurrent;
} elseif ($returnVisitedIfOutOfSection && $this->cacheSectionVisited) {
return $this->cacheSectionVisited;
} elseif ($returnDefaultIfOutOfSections && $this->cacheSectionDefault) {
return $this->cacheSectionDefault;
}

$userCurrent = $this->security->getUser(); $userCurrent = $this->security->getUser();
$merchantCurrent = $this->merchantResolver->getCurrent(); $merchantCurrent = $this->merchantResolver->getCurrent();
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent); $sectionStore = $this->sectionStore->setMerchant($merchantCurrent);
} }


if ($sectionCurrent) { if ($sectionCurrent) {
$this->cacheSectionCurrent = $sectionCurrent;
return $sectionCurrent; return $sectionCurrent;
} elseif ($returnVisitedIfOutOfSection && $currentVisitedSection) { } elseif ($returnVisitedIfOutOfSection && $currentVisitedSection) {
$this->cacheSectionVisited = $currentVisitedSection;
return $currentVisitedSection; return $currentVisitedSection;
} elseif ($returnDefaultIfOutOfSections && $sectionDefault) { } elseif ($returnDefaultIfOutOfSections && $sectionDefault) {
$this->cacheSectionDefault = $sectionDefault;
return $sectionDefault; return $sectionDefault;
} }



Loading…
Cancel
Save