feat: performance improvements

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent 4decaa6789
commit 1e464cef0a
6 changed files with 122 additions and 103 deletions
@@ -8,7 +8,6 @@ use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\Form\Model\BookingDto;
use Carbon\CarbonImmutable;
use Spatie\Blink\Blink;
/**
* Service for evaluating participant eligibility for booking.
@@ -18,11 +17,13 @@ use Spatie\Blink\Blink;
* for eligibility checks used by both the conditional field state system and
* the view layer via Twig extension.
*
* Results are cached per request using Blink to avoid redundant calculations
* Results are cached per request using instance-level arrays to avoid redundant calculations
* when checking the same participant multiple times.
*/
class ParticipantEligibilityService
{
/** @var array<string, bool> Request-scoped cache for participant eligibility */
private array $eligibilityCache = [];
/**
* Checks if a participant is eligible for booking.
*
@@ -52,7 +53,7 @@ class ParticipantEligibilityService
$participantIndex
);
return Blink::global()->once($cacheKey, function () use ($bookingDto, $participantIndex) {
return $this->eligibilityCache[$cacheKey] ??= (function () use ($bookingDto, $participantIndex) {
$allSkiPasses = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_SKI_PASS, true, true);
$availableSkiPasses = array_filter(
$allSkiPasses,
@@ -60,7 +61,7 @@ class ParticipantEligibilityService
);
return !empty($availableSkiPasses);
});
})();
}
/**