fix: remove form options cache causing issues
This commit is contained in:
@@ -36,9 +36,6 @@ use App\Service\ServiceAvailabilityCalculator;
|
||||
*/
|
||||
class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
{
|
||||
/** @var array<string, array<string, mixed>> Request-scoped cache for field options */
|
||||
private array $optionsCache = [];
|
||||
|
||||
/**
|
||||
* Initializes the provider with required dependencies.
|
||||
*
|
||||
@@ -61,39 +58,6 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves form field options with request-scoped caching.
|
||||
*
|
||||
* Overrides parent to add instance-level caching, preventing redundant
|
||||
* field option calculations when the same field is accessed multiple times
|
||||
* during form building (happens ~16 times per participant × 50 participants = 800 calls).
|
||||
*
|
||||
* Cache key includes: field name, participant index, mode, and date of birth.
|
||||
* The cache is automatically cleared between requests since the service is request-scoped.
|
||||
*
|
||||
* @param string $fieldName The name of the field to configure
|
||||
* @param BookingDto $bookingDto The current booking data for context
|
||||
* @param int $participantIndex The index of the participant being configured
|
||||
* @param array $options Additional options to customize field behavior
|
||||
*
|
||||
* @return array<string, mixed> Symfony form field options, or empty array if field not supported
|
||||
*/
|
||||
public function getFieldOptions(string $fieldName, BookingDto $bookingDto, int $participantIndex, array $options = []): array
|
||||
{
|
||||
// Generate cache key based on factors that affect field options
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
$cacheKey = sprintf(
|
||||
'%s_%d_%s_%s',
|
||||
$fieldName,
|
||||
$participantIndex,
|
||||
$bookingDto->getMode(),
|
||||
$participant?->dateOfBirth?->format('Y-m-d') ?? 'no_dob'
|
||||
);
|
||||
|
||||
// Return cached result if available, otherwise compute and cache
|
||||
return $this->optionsCache[$cacheKey] ??= parent::getFieldOptions($fieldName, $bookingDto, $participantIndex, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all field option providers during service initialization.
|
||||
*
|
||||
@@ -494,15 +458,7 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'placeholder' => false, // Disable default placeholder - synthetic "keine Versicherung gewünscht" option injected instead
|
||||
'choices' => $this->getEligibleInsurances($bookingDto, $participantIndex),
|
||||
'choice_value' => 'id',
|
||||
'choice_label' => function (?Insurance $insurance) {
|
||||
$label = $insurance->label;
|
||||
|
||||
if (null !== $insurance->price && $insurance->price > 0) {
|
||||
$label .= sprintf(' (€%s)', number_format($insurance->price, 2, ',', '.'));
|
||||
}
|
||||
|
||||
return $label;
|
||||
},
|
||||
'choice_label' => fn (?Insurance $insurance) => $insurance?->label,
|
||||
];
|
||||
|
||||
// Purchase voucher field provider - redemption code for vouchers that apply to complete booking
|
||||
|
||||
Reference in New Issue
Block a user