fix: revoke caching of bpn product data
This commit is contained in:
@@ -32,30 +32,20 @@ use EP\EpProducts\Domain\Model\Product;
|
|||||||
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
||||||
use EP\EpProducts\Utility\BookingUrlUtility;
|
use EP\EpProducts\Utility\BookingUrlUtility;
|
||||||
use League\Period\Period;
|
use League\Period\Period;
|
||||||
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
|
|
||||||
|
|
||||||
class ContingentDataService
|
class ContingentDataService
|
||||||
{
|
{
|
||||||
public const CACHE_TTL = 60 * 60;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ContingentRepository
|
* @var ContingentRepository
|
||||||
*/
|
*/
|
||||||
protected $contingentRepository;
|
protected $contingentRepository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var FrontendInterface
|
|
||||||
*/
|
|
||||||
private $cache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContingentRepository $contingentRepository
|
* @param ContingentRepository $contingentRepository
|
||||||
* @param FrontendInterface $cache
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ContingentRepository $contingentRepository, FrontendInterface $cache)
|
public function __construct(ContingentRepository $contingentRepository)
|
||||||
{
|
{
|
||||||
$this->contingentRepository = $contingentRepository;
|
$this->contingentRepository = $contingentRepository;
|
||||||
$this->cache = $cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,21 +56,15 @@ class ContingentDataService
|
|||||||
*/
|
*/
|
||||||
public function getAvailableContingents(Hotel $hotel, Product $product)
|
public function getAvailableContingents(Hotel $hotel, Product $product)
|
||||||
{
|
{
|
||||||
$key = 'contingents_'.sha1($hotel->getUid().$product->getUid());
|
$data = $this->contingentRepository->getAvailableContingents($hotel, $product);
|
||||||
|
$contingents = [];
|
||||||
if (false === $contingents = $this->cache->get($key)) {
|
foreach ($data as $row) {
|
||||||
$data = $this->contingentRepository->getAvailableContingents($hotel, $product);
|
$contingents[$row['date']] = [
|
||||||
$contingents = [];
|
'date' => $row['date'],
|
||||||
foreach ($data as $row) {
|
'minNights' => $row['minNights'],
|
||||||
$contingents[$row['date']] = [
|
'total' => $row['total'],
|
||||||
'date' => $row['date'],
|
'capacity' => $row['capacity'],
|
||||||
'minNights' => $row['minNights'],
|
];
|
||||||
'total' => $row['total'],
|
|
||||||
'capacity' => $row['capacity'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cache->set($key, $contingents, [], self::CACHE_TTL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $contingents;
|
return $contingents;
|
||||||
@@ -100,34 +84,28 @@ class ContingentDataService
|
|||||||
string $dateTo,
|
string $dateTo,
|
||||||
Hotel $hotel,
|
Hotel $hotel,
|
||||||
Product $product,
|
Product $product,
|
||||||
$template = 'base'
|
string $template = 'base'
|
||||||
) {
|
) {
|
||||||
$key = 'rooms_'.sha1($dateFrom.$dateTo.$hotel->getUid().$product->getUid());
|
$data = $this->contingentRepository->getAvailableRooms($dateFrom, $dateTo, $hotel, $product);
|
||||||
|
$period = new Period($dateFrom, $dateTo);
|
||||||
|
$nights = $period->dateInterval()->format('%a');
|
||||||
|
$rooms = [];
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$row['bookingUrl'] = BookingUrlUtility::generateUrl([
|
||||||
|
'bookingId' => $row['busProId'],
|
||||||
|
'hotelId' => $row['hotelBusProId'],
|
||||||
|
'dateEnd' => $dateTo,
|
||||||
|
'template' => $template,
|
||||||
|
]);
|
||||||
|
|
||||||
if (false === $rooms = $this->cache->get($key)) {
|
$row['summer'] = $row['season'] === 's';
|
||||||
$data = $this->contingentRepository->getAvailableRooms($dateFrom, $dateTo, $hotel, $product);
|
|
||||||
$period = new Period($dateFrom, $dateTo);
|
|
||||||
$nights = $period->dateInterval()->format('%a');
|
|
||||||
$rooms = [];
|
|
||||||
foreach ($data as $row) {
|
|
||||||
$row['bookingUrl'] = BookingUrlUtility::generateUrl([
|
|
||||||
'bookingId' => $row['busProId'],
|
|
||||||
'hotelId' => $row['hotelBusProId'],
|
|
||||||
'dateEnd' => $dateTo,
|
|
||||||
'template' => $template,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$row['summer'] = $row['season'] === 's';
|
$row['servicesIncluded'] = unserialize($row['servicesIncluded'], ['allowed_classes' => false]);
|
||||||
|
$row['servicesOptional'] = unserialize($row['servicesOptional'], ['allowed_classes' => false]);
|
||||||
|
|
||||||
$row['servicesIncluded'] = unserialize($row['servicesIncluded'], ['allowed_classes' => false]);
|
$row['priceForSelection'] = $row['price'] + ($nights - $row['minNights']) * $row['additionalNightPrice'];
|
||||||
$row['servicesOptional'] = unserialize($row['servicesOptional'], ['allowed_classes' => false]);
|
|
||||||
|
|
||||||
$row['priceForSelection'] = $row['price'] + ($nights - $row['minNights']) * $row['additionalNightPrice'];
|
$rooms[] = $row;
|
||||||
|
|
||||||
$rooms[] = $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cache->set($key, $rooms, [], self::CACHE_TTL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rooms;
|
return $rooms;
|
||||||
|
|||||||
@@ -33,15 +33,12 @@ use EP\EpProducts\Domain\Repository\DateRepository;
|
|||||||
use EP\EpProducts\Domain\Repository\ProductRepository;
|
use EP\EpProducts\Domain\Repository\ProductRepository;
|
||||||
use EP\EpProducts\Utility\BookingUrlUtility;
|
use EP\EpProducts\Utility\BookingUrlUtility;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
|
|
||||||
use TYPO3\CMS\Core\SingletonInterface;
|
use TYPO3\CMS\Core\SingletonInterface;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
||||||
|
|
||||||
class DateService implements SingletonInterface
|
class DateService implements SingletonInterface
|
||||||
{
|
{
|
||||||
public const CACHE_TTL = 60 * 60;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ProductRepository
|
* @var ProductRepository
|
||||||
*/
|
*/
|
||||||
@@ -62,11 +59,6 @@ class DateService implements SingletonInterface
|
|||||||
*/
|
*/
|
||||||
protected $uriBuilder;
|
protected $uriBuilder;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var FrontendInterface
|
|
||||||
*/
|
|
||||||
protected $cache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
@@ -84,22 +76,19 @@ class DateService implements SingletonInterface
|
|||||||
* @param DateRepository $dateRepository
|
* @param DateRepository $dateRepository
|
||||||
* @param FilterService $filterService
|
* @param FilterService $filterService
|
||||||
* @param UriBuilder $uriBuilder
|
* @param UriBuilder $uriBuilder
|
||||||
* @param FrontendInterface $cache
|
|
||||||
*/
|
*/
|
||||||
public function __construct
|
public function __construct
|
||||||
(
|
(
|
||||||
ProductRepository $productRepository,
|
ProductRepository $productRepository,
|
||||||
DateRepository $dateRepository,
|
DateRepository $dateRepository,
|
||||||
FilterService $filterService,
|
FilterService $filterService,
|
||||||
UriBuilder $uriBuilder,
|
UriBuilder $uriBuilder
|
||||||
FrontendInterface $cache
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->productRepository = $productRepository;
|
$this->productRepository = $productRepository;
|
||||||
$this->filterService = $filterService;
|
$this->filterService = $filterService;
|
||||||
$this->dateRepository = $dateRepository;
|
$this->dateRepository = $dateRepository;
|
||||||
$this->uriBuilder = $uriBuilder;
|
$this->uriBuilder = $uriBuilder;
|
||||||
$this->cache = $cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,19 +114,10 @@ class DateService implements SingletonInterface
|
|||||||
$filterSettings = $this->filterService->getNormalizedFilterSettings();
|
$filterSettings = $this->filterService->getNormalizedFilterSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
$keyValues = $product->getUid().$hotel->getUid().serialize($filterSettings);
|
|
||||||
$keyValues.= $date ? $date->getUid() : 0;
|
|
||||||
$key = 'pricetable_'.sha1($keyValues);
|
|
||||||
|
|
||||||
if (false === $priceTableData = $this->cache->get($key)) {
|
|
||||||
$priceTableData = $this->productRepository->getPricetable($product, $hotel, $filterSettings, $date);
|
|
||||||
$this->cache->set($key, $priceTableData, ['ep_products'], self::CACHE_TTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
$nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDates(), true);
|
$nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDates(), true);
|
||||||
|
|
||||||
return $this->preprocessPriceTable([
|
return $this->preprocessPriceTable([
|
||||||
'priceTableData' => $priceTableData,
|
'priceTableData' => $this->productRepository->getPricetable($product, $hotel, $filterSettings, $date),
|
||||||
'template' => $template,
|
'template' => $template,
|
||||||
'paCode' => $paCode,
|
'paCode' => $paCode,
|
||||||
'isDayTrip' => $product->isDaytrip(),
|
'isDayTrip' => $product->isDaytrip(),
|
||||||
@@ -174,13 +154,7 @@ class DateService implements SingletonInterface
|
|||||||
$filterSettings = $this->filterService->getNormalizedFilterSettings();
|
$filterSettings = $this->filterService->getNormalizedFilterSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = 'datestable_'.sha1($product->getUid().$hotel->getUid().serialize($filterSettings));
|
return $this->productRepository->getAvailableDates($product, $hotel, $filterSettings);
|
||||||
if (false === $datesTableData = $this->cache->get($key)) {
|
|
||||||
$datesTableData = $this->productRepository->getAvailableDates($product, $hotel, $filterSettings);
|
|
||||||
$this->cache->set($key, $datesTableData, ['ep_products'], self::CACHE_TTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $datesTableData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,14 +170,8 @@ class DateService implements SingletonInterface
|
|||||||
|
|
||||||
public function getEventPriceTable(Product $product, int $maxPax = 99, string $template = 'base'): array
|
public function getEventPriceTable(Product $product, int $maxPax = 99, string $template = 'base'): array
|
||||||
{
|
{
|
||||||
$key = 'pricetable_'.sha1($product->getUid());
|
|
||||||
if (false === $priceTableData = $this->cache->get($key)) {
|
|
||||||
$priceTableData = $this->productRepository->getEventPriceTable($product);
|
|
||||||
$this->cache->set($key, $priceTableData, ['ep_products'], self::CACHE_TTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->preprocessEventPriceTable([
|
return $this->preprocessEventPriceTable([
|
||||||
'priceTableData' => $priceTableData,
|
'priceTableData' => $this->productRepository->getEventPriceTable($product),
|
||||||
'maxPax' => $maxPax,
|
'maxPax' => $maxPax,
|
||||||
'template' => $template,
|
'template' => $template,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -29,13 +29,10 @@ namespace EP\EpProducts\Service;
|
|||||||
use EP\EpProducts\Domain\Model\Hotel;
|
use EP\EpProducts\Domain\Model\Hotel;
|
||||||
use EP\EpProducts\Domain\Repository\HotelRepository;
|
use EP\EpProducts\Domain\Repository\HotelRepository;
|
||||||
use EP\EpProducts\Domain\Repository\ProductRepository;
|
use EP\EpProducts\Domain\Repository\ProductRepository;
|
||||||
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
|
|
||||||
use TYPO3\CMS\Core\SingletonInterface;
|
use TYPO3\CMS\Core\SingletonInterface;
|
||||||
|
|
||||||
class ProductDataService implements SingletonInterface
|
class ProductDataService implements SingletonInterface
|
||||||
{
|
{
|
||||||
public const CACHE_TTL = 60 * 60;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ProductRepository
|
* @var ProductRepository
|
||||||
*/
|
*/
|
||||||
@@ -56,11 +53,6 @@ class ProductDataService implements SingletonInterface
|
|||||||
*/
|
*/
|
||||||
protected $hotelImageService;
|
protected $hotelImageService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var FrontendInterface
|
|
||||||
*/
|
|
||||||
protected $cache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ProductRepository $productRepository
|
* @param ProductRepository $productRepository
|
||||||
* @param HotelRepository $hotelRepository
|
* @param HotelRepository $hotelRepository
|
||||||
@@ -71,14 +63,12 @@ class ProductDataService implements SingletonInterface
|
|||||||
ProductRepository $productRepository,
|
ProductRepository $productRepository,
|
||||||
HotelRepository $hotelRepository,
|
HotelRepository $hotelRepository,
|
||||||
HotelImageService $hotelImageService,
|
HotelImageService $hotelImageService,
|
||||||
ProductImageService $productImageService,
|
ProductImageService $productImageService
|
||||||
FrontendInterface $cache
|
|
||||||
) {
|
) {
|
||||||
$this->productRepository = $productRepository;
|
$this->productRepository = $productRepository;
|
||||||
$this->hotelRepository = $hotelRepository;
|
$this->hotelRepository = $hotelRepository;
|
||||||
$this->productImageService = $productImageService;
|
$this->productImageService = $productImageService;
|
||||||
$this->hotelImageService = $hotelImageService;
|
$this->hotelImageService = $hotelImageService;
|
||||||
$this->cache = $cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,13 +78,8 @@ class ProductDataService implements SingletonInterface
|
|||||||
*/
|
*/
|
||||||
public function getTeaser(array $filterSettings): ?array
|
public function getTeaser(array $filterSettings): ?array
|
||||||
{
|
{
|
||||||
$key = 'teaser_group_'.sha1(serialize($filterSettings));
|
$teaserData = $this->productRepository->getTeasers($filterSettings);
|
||||||
|
$teasers = $this->preprocessTeasergroup($teaserData);
|
||||||
if (false === $teasers = $this->cache->get($key)) {
|
|
||||||
$teaserData = $this->productRepository->getTeasers($filterSettings);
|
|
||||||
$teasers = $this->preprocessTeasergroup($teaserData);
|
|
||||||
$this->cache->set($key, $teasers, ['ep_products'], self::CACHE_TTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 === count($teasers)) {
|
if (0 === count($teasers)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -112,13 +97,8 @@ class ProductDataService implements SingletonInterface
|
|||||||
*/
|
*/
|
||||||
public function getTeasergroup(array $filterSettings, array $excludedConceptUids = [], int $limit = 0): array
|
public function getTeasergroup(array $filterSettings, array $excludedConceptUids = [], int $limit = 0): array
|
||||||
{
|
{
|
||||||
$key = 'teaser_group_'.sha1(serialize($filterSettings).serialize($excludedConceptUids));
|
$teaserData = $this->productRepository->getTeasers($filterSettings, $excludedConceptUids);
|
||||||
|
$teasers = $this->preprocessTeasergroup($teaserData);
|
||||||
if (false === $teasers = $this->cache->get($key)) {
|
|
||||||
$teaserData = $this->productRepository->getTeasers($filterSettings, $excludedConceptUids);
|
|
||||||
$teasers = $this->preprocessTeasergroup($teaserData);
|
|
||||||
$this->cache->set($key, $teasers, ['ep_products'], self::CACHE_TTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($limit > 0) {
|
if ($limit > 0) {
|
||||||
return \array_slice($teasers, 0, $limit);
|
return \array_slice($teasers, 0, $limit);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<onChange>reload</onChange>
|
<onChange>reload</onChange>
|
||||||
<config>
|
<config>
|
||||||
<type>select</type>
|
<type>select</type>
|
||||||
|
<renderType>selectSingle</renderType>
|
||||||
<default>Pricetable->event</default>
|
<default>Pricetable->event</default>
|
||||||
<items type="array">
|
<items type="array">
|
||||||
<numIndex index="1" type="array">
|
<numIndex index="1" type="array">
|
||||||
|
|||||||
@@ -27,15 +27,3 @@ services:
|
|||||||
EP\EpProducts\Service\ProductImageService:
|
EP\EpProducts\Service\ProductImageService:
|
||||||
arguments:
|
arguments:
|
||||||
$cache: '@cache.ep_cache'
|
$cache: '@cache.ep_cache'
|
||||||
|
|
||||||
EP\EpProducts\Service\DateService:
|
|
||||||
arguments:
|
|
||||||
$cache: '@cache.ep_cache'
|
|
||||||
|
|
||||||
EP\EpProducts\Service\ProductDataService:
|
|
||||||
arguments:
|
|
||||||
$cache: '@cache.ep_cache'
|
|
||||||
|
|
||||||
EP\EpProducts\Service\ContingentDataService:
|
|
||||||
arguments:
|
|
||||||
$cache: '@cache.ep_cache'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user