Sfoglia il codice sorgente

[Frontend] Home : optimisations / cache

develop
Guillaume Bourgeois 2 anni fa
parent
commit
1d1ce7d2b6
3 ha cambiato i file con 57 aggiunte e 2 eliminazioni
  1. +2
    -0
      Builder/Product/ProductFamilyBuilder.php
  2. +54
    -1
      Repository/Product/ProductFamilyStore.php
  3. +1
    -1
      Solver/Product/ProductFamilySolver.php

+ 2
- 0
Builder/Product/ProductFamilyBuilder.php Vedi File

@@ -2,6 +2,8 @@

namespace Lc\CaracoleBundle\Builder\Product;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;

class ProductFamilyBuilder
{


+ 54
- 1
Repository/Product/ProductFamilyStore.php Vedi File

@@ -11,6 +11,8 @@ use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;

class ProductFamilyStore extends AbstractStore
{
@@ -19,13 +21,16 @@ class ProductFamilyStore extends AbstractStore

protected ProductFamilyRepositoryQuery $query;
protected PriceSolver $priceSolver;
protected CacheInterface $cache;

public function __construct(
ProductFamilyRepositoryQuery $query,
PriceSolver $priceSolver
PriceSolver $priceSolver,
CacheInterface $cache
) {
$this->query = $query;
$this->priceSolver = $priceSolver;
$this->cache = $cache;
}

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
@@ -116,6 +121,25 @@ class ProductFamilyStore extends AbstractStore
return $this->getWithReductions($results, $user, false, $organizeByParentCategory);
}

public function getCachedNovelty($user = null, $organizeByParentCategory = true, $query = null): array
{
$productFamilyStore = $this;
return $this->cache->get($this->getCacheKeyNovelty(), function (ItemInterface $item) use ($productFamilyStore, $user, $organizeByParentCategory, $query) {
$item->expiresAfter(3600);
return $productFamilyStore->getNovelty($user, $organizeByParentCategory, $query);
});
}

public function deleteCacheNovelty(): void
{
$this->cache->delete($this->getCacheKeyNovelty());
}

public function getCacheKeyNovelty()
{
return 'products_novelty_'.$this->section->getId();
}

// getProductFamiliesOrganics
public function getOrganic($user = null, $organizeByParentCategory = true, $query = null)
{
@@ -134,6 +158,31 @@ class ProductFamilyStore extends AbstractStore
return $this->getWithReductions($this->getOnline($query), $user, false, $organizeByParentCategory, true);
}

public function getCachedDiscount($user = null, $organizeByParentCategory = true, $query = null): array
{
$productFamilyStore = $this;

return $this->cache->get($this->getCacheKeyDiscount(), function (ItemInterface $item) use ($productFamilyStore, $user, $organizeByParentCategory, $query) {
$item->expiresAfter(3600);
return $productFamilyStore->getDiscount($user, $organizeByParentCategory, $query);
});
}

public function deleteCacheDiscount(): void
{
$this->cache->delete($this->getCacheKeyDiscount());
}

public function getCacheKeyDiscount()
{
return 'products_discount_'.$this->section->getId();
}

public function loadAllDatas(ProductFamilyInterface $productFamily)
{
$productFamily->getProductFamilySectionProperties()->toArray();
}

// getProductFamiliesFavorites
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null)
{
@@ -227,6 +276,10 @@ class ProductFamilyStore extends AbstractStore

$productFamiliesToReturn = array();
foreach ($productFamilies as $productFamily) {

// Cache : chargement de toutes les données manquantes (fetch eager ne fonctionne pas)
$this->loadAllDatas($productFamily);

foreach ($reductionCatalogs as $reductionCatalog) {
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false;


+ 1
- 1
Solver/Product/ProductFamilySolver.php Vedi File

@@ -152,7 +152,7 @@ class ProductFamilySolver
if ($productFamily->getTaxRate()) {
return $productFamily->getTaxRate();
} else {
return $productFamily->getProductFamilySectionProperties()[0]->getSection()->getMerchant()->getTaxRate();
return $this->getMerchant($productFamily)->getTaxRate();
}
}


Loading…
Annulla
Salva