From d0cb951550e63546845a90952423750f7bfcce23 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 6 Sep 2021 16:11:04 +0200 Subject: [PATCH] Do not break performance when no postponed date exists Some sites do not use postponed_date at all. It would be a massive performance issue to still search for them for each and every date instance that is created. This small addition will solve the issue for those pages. It will still once at least one internal reference is added. We could then try to add proxies which are build and added, but don't use the DB. That way the performance would still be okay, and data will only be fetched when used. --- Classes/Extbase/AddSpecialProperties.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Classes/Extbase/AddSpecialProperties.php b/Classes/Extbase/AddSpecialProperties.php index 287495b..77243d9 100644 --- a/Classes/Extbase/AddSpecialProperties.php +++ b/Classes/Extbase/AddSpecialProperties.php @@ -38,17 +38,32 @@ class AddSpecialProperties */ private $dataMapper; + /** + * Internal info to speed things up if we know there are none. + * @var bool + */ + private $doPostponedDatesExist = true; + public function __construct( ConnectionPool $connectionPool, DataMapper $dataMapper ) { $this->connectionPool = $connectionPool; $this->dataMapper = $dataMapper; + + $qb = $this->connectionPool->getQueryBuilderForTable('tx_events_domain_model_date'); + $qb->count('uid'); + $qb->from('tx_events_domain_model_date'); + $qb->where($qb->expr()->gt('postponed_date', $qb->createNamedParameter(0))); + $this->doPostponedDatesExist = $qb->execute()->fetchColumn() > 0; } public function __invoke(AfterObjectThawedEvent $event): void { - if ($event->getObject() instanceof Date) { + if ( + $this->doPostponedDatesExist + && $event->getObject() instanceof Date + ) { /** @var Date $date */ $date = $event->getObject(); $date->_setProperty('originalDate', $this->getOriginalDate($date->_getProperty('_localizedUid')));