-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Currently, when using #[PurgeOn] with routes where at least on route parameter is mandatory, Purgatory determines whether a subscription should be skipped after resolving all route parameters.
However, if the configuration provided to PurgeOn includes expressions that may return null, the route cannot be generated, leading Purgatory to skip the subscription entirely. The inefficiency lies in the fact that all route parameters are resolved before this decision is made.
Proposed Improvement
Instead of resolving all parameters first and then deciding whether to skip the purge, we can optimize this process by:
- Early Termination – If a resolved route parameter is null, and the corresponding parameter is mandatory in the route, we should immediately skip the subscription without resolving any remaining parameters.
- Optimized Evaluation Order – Route parameters containing nullsafe operators (e.g.
assoc1?.id) should be evaluated first. If such an expression results in null, we can potentially skip the subscription earlier, avoiding unnecessary processing.
Example:
#[PurgeOn(Event::class,
routeParams: [
'param1' => 'id',
'param2' => 'assoc1?.id',
'param3' => 'assoc2?.id'
]
)]If resolving param2 returns null, there is no need to resolve param3, as the entire subscription will be skipped. Additionaly, we can move resolving param1 to the end because it does not contain nullsafe operators.
Currently, subscription is skipped here:
purgatory-bundle/src/RouteProvider/AbstractEntityRouteProvider.php
Lines 116 to 118 in 4176b9a
| if (array_any($routeParamValues, static fn (array $value): bool => [] === $value)) { | |
| return []; // skip entire subscription if a certain param value is missing | |
| } |
This check should be made after each route parameter is resolved