feat: load availability data once per booking session
This commit is contained in:
@@ -138,9 +138,8 @@ class Step2Controller extends AbstractController
|
||||
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Fetch fresh availabilities when entering participant form
|
||||
// This ensures up-to-date data and populates cache for subsequent HTMX refreshes
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel, cached: false);
|
||||
// Use cached availability data (populated during booking init)
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
|
||||
|
||||
// Create form with booking_context option
|
||||
$form = $this->createParticipantForm($bookingDto, $index);
|
||||
|
||||
@@ -168,9 +168,8 @@ class IndexController extends AbstractController
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
// Fetch fresh availabilities when entering participant form
|
||||
// This ensures up-to-date data and populates cache for subsequent HTMX refreshes
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel, cached: false);
|
||||
// Use cached availability data (populated during booking init)
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
|
||||
|
||||
// Create wrapper DTO for email uniqueness validation
|
||||
$wrapper = new ParticipantEditDto(
|
||||
|
||||
@@ -75,7 +75,8 @@ class BookingEditDataLoaderService
|
||||
}
|
||||
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId);
|
||||
// Using cached: true populates the cache for subsequent participant form loads
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId, cached: true);
|
||||
|
||||
if (null === $mutableData || null === $availabilities) {
|
||||
return null;
|
||||
|
||||
@@ -236,7 +236,8 @@ class BookingService
|
||||
}
|
||||
|
||||
// Fetch and patch availability data (includes allowedBookingStatus from API)
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($dateId);
|
||||
// Using cached: true populates the cache for subsequent participant form loads
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($dateId, cached: true);
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($travelData, $availabilities);
|
||||
}
|
||||
|
||||
@@ -523,19 +523,18 @@ class TravelDataService
|
||||
* Gets availability data for a travel date.
|
||||
*
|
||||
* @param int $dateId The travel date ID for API call
|
||||
* @param bool $cached Whether to use cached data (default: false, TTL when cached: 300 seconds)
|
||||
* @param int $ttl Cache TTL in seconds when $cached is true (default: 300 seconds)
|
||||
* @param bool $cached Whether to use cached data (default: false, TTL when cached: 600 seconds)
|
||||
* @param int $ttl Cache TTL in seconds when $cached is true (default: 600 seconds)
|
||||
*
|
||||
* @return ServiceAvailabilityResponse|null The availability data or null if not available or error occurred
|
||||
*/
|
||||
public function getAvailabilityData(int $dateId, bool $cached = false, int $ttl = 300): ?ServiceAvailabilityResponse
|
||||
public function getAvailabilityData(int $dateId, bool $cached = false, int $ttl = 600): ?ServiceAvailabilityResponse
|
||||
{
|
||||
if ($cached) {
|
||||
$cacheKey = sprintf('availability_%d', $dateId);
|
||||
|
||||
try {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId, $ttl) {
|
||||
// Short TTL - availability is volatile and changes with bookings
|
||||
$item->expiresAfter($ttl);
|
||||
|
||||
return $this->fetchAvailabilityData($dateId);
|
||||
|
||||
Reference in New Issue
Block a user