feat: performance improvements
This commit is contained in:
@@ -20,6 +20,9 @@ use App\Form\Model\ParticipantDto;
|
||||
*/
|
||||
class BookingPriceCalculatorService
|
||||
{
|
||||
/** @var array<string, float> Request-scoped cache for participant prices */
|
||||
private array $participantPriceCache = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly ParticipantEligibilityService $participantEligibilityService,
|
||||
private readonly InsuranceService $insuranceService,
|
||||
@@ -324,22 +327,45 @@ class BookingPriceCalculatorService
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$totalPrice = 0.0;
|
||||
// Generate cache key based on participant state that affects pricing
|
||||
$stateComponents = [
|
||||
'room' => $participant->assignedRoomId ?? 'none',
|
||||
'skiPass' => $participant->skiPass?->id ?? 'none',
|
||||
'rentalInsurance' => $participant->rentalInsurance?->id ?? 'none',
|
||||
'transportationOut' => $participant->transportationOutbound?->id ?? 'none',
|
||||
'transportationIn' => $participant->transportationInbound?->id ?? 'none',
|
||||
'pickup' => $participant->pickup?->id ?? 'none',
|
||||
'parking' => $participant->parkingService?->id ?? 'none',
|
||||
'courses' => implode('_', array_map(fn ($s) => $s->id, $participant->courses ?? [])),
|
||||
'additionalServices' => implode('_', array_map(fn ($s) => $s->id, $participant->additionalServices ?? [])),
|
||||
'board' => implode('_', array_map(fn ($s) => $s->id, $participant->board ?? [])),
|
||||
'rentals' => implode('_', array_map(fn ($s) => $s->id, $participant->rentals ?? [])),
|
||||
];
|
||||
|
||||
// Add room price if participant is assigned to a room
|
||||
if (null !== $participant->assignedRoomId) {
|
||||
$room = $this->getRoomById($bookingDto, $participant->assignedRoomId);
|
||||
if (null !== $room && null !== $room->price) {
|
||||
// Each participant pays the full room price
|
||||
$totalPrice += $room->price;
|
||||
$cacheKey = sprintf(
|
||||
'participant_price_%d_%s',
|
||||
$participantIndex,
|
||||
md5(json_encode($stateComponents))
|
||||
);
|
||||
|
||||
return $this->participantPriceCache[$cacheKey] ??= (function () use ($bookingDto, $participant) {
|
||||
$totalPrice = 0.0;
|
||||
|
||||
// Add room price if participant is assigned to a room
|
||||
if (null !== $participant->assignedRoomId) {
|
||||
$room = $this->getRoomById($bookingDto, $participant->assignedRoomId);
|
||||
if (null !== $room && null !== $room->price) {
|
||||
// Each participant pays the full room price
|
||||
$totalPrice += $room->price;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add service prices for this participant (excluding insurance)
|
||||
// For insurance eligibility calculation, only include services marked with versicherungsberechnung='J'
|
||||
$totalPrice += $this->calculateParticipantServiceTotal($participant, false, null, true);
|
||||
// Add service prices for this participant (excluding insurance)
|
||||
// For insurance eligibility calculation, only include services marked with versicherungsberechnung='J'
|
||||
$totalPrice += $this->calculateParticipantServiceTotal($participant, false, null, true);
|
||||
|
||||
return $totalPrice;
|
||||
return $totalPrice;
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user