Add a configurable limit for the search window#5293
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #5293 +/- ##
=============================================
+ Coverage 65.92% 66.60% +0.68%
- Complexity 14820 15297 +477
=============================================
Files 1773 1790 +17
Lines 68789 69406 +617
Branches 7289 7310 +21
=============================================
+ Hits 45346 46225 +879
+ Misses 20960 20704 -256
+ Partials 2483 2477 -6
☔ View full report in Codecov by Sentry. |
|
The description says that there are unit tests but I can't see any. |
|
No unit tests, I use the check mark to state that the existing ones are passing. |
|
No, my bad, I mixed up with the other JSON error mapping PR. This one needs a unit test. |
|
It's not super hard to write tests for the JAXB resource classes, you can simply instantiate them. I did it here: It's not terribly elegant but it works, but you're right: in this case you need something simpler. |
|
Added validation for zero or negative search window. It is now: |
|
That was a bit too quick, it fails for reverse search :-) |
|
@t2gran why do we set the duration to zero there? |
70b1d23 to
11e952f
Compare
|
A zero-length search window is valid, only negative search windows should be rejected --> validation adjusted accordingly. |
|
FYI: searchWindow=0s is used to run plain Raptor without minute iterations (RangeRaptor). This is used to produce heuristics. |
|
What would be an appropriate name for a router config parameter specifying the maximum search window that can be set through the API? |
5290a17
|
Added support for configurable max search window with default to 24 hours. |
4799b04 to
5b4686a
Compare
| } | ||
|
|
||
| private boolean hasMaxSearchWindow() { | ||
| return !Duration.ZERO.equals(maxSearchWindow); |
There was a problem hiding this comment.
I find it easier to understand if null is used for UNSET, and NOT Duration.ZERO. Add @nullable to the field and setter.
| .description( | ||
| "Maximum search window that can be set through the searchWindow API parameter." | ||
| ) | ||
| .asDuration(Duration.ofHours(24)); |
There was a problem hiding this comment.
The default value should not be defined here - not the responsibility of this class. Can you remind me that we fix this after this is merged? This follows an existing pattern and I would like to fix all of them - and that does not belong in this PR.
leonardehrenfried
left a comment
There was a problem hiding this comment.
The code here looks good but what happens it if you set transit.dynamicSearchWindow.maxWindow=36h and the computed dynamic window is higher than this max value?
|
Tested locally with maxSearchWindow=65m and dynamicSearchWindow.maxWindow=5h: when omitting the searchWindow parameter for a given query, a dynamic search window of 70m was used: thus the parameter maxSearchWindow was ignored. Is this what we want? |
|
I think I'm fine with this behaviour if we mention it in the docs. |
8b7f115 to
79ba498
Compare
Summary
This PR ensures that the search window cannot exceed a configurable duration, with a default set to 24 hours.
Due to the way timetable data are collected before a Raptor trip search, using a search window larger than 24 hours may lead to inconsistent search results.
Limiting the search window prevents also potential performance issues.
The API returns the following response with HTTP code 200:
Issue
No
Unit tests
Added unit tests
Documentation
Updated documentation