feat: performance improvements
This commit is contained in:
@@ -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);
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user