Stop caching autosuggest requests #3566
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
This PR changes the way authenticated requests for autosuggest are fired. These requests are used so the Elasticsearch hosting provider (EP.io, for example) knows which parameters are allowed in a query sent via JS, preventing anonymous users to send a query asking for shop orders, for example.
In #1890 (EP 3.5.2, in 2020) we introduced an authenticated request sent before the sync is started and when the weighting dashboard is saved. This request has a header
EP-Set-Autosuggest=true
. Before that, any request sendingep-search-term=search test
orep-search-term=ep_autosuggest_placeholder
would set those values. To avoid sending a request per page load, EP cached the request sent.The way we were caching it depended on the presence or absence of an external object cache: if present, we would cache a request per different query, if absent, we would just cache one query. Although that was made to allow for different autosuggest queries, it really doesn't fix the problem, as we can only have one set of allowed parameters.
This PR removes those cached requests, only sending a request to set allowed parameters before a sync or when the weighting dashboard is saved. If people want to run different autosuggest queries with different sets of allowed parameters, they can pass the superset of parameters (including everything) using the
ep_autosuggest_query_args
filter and checking if$_GET['ep_epio_set_autosuggest']
is set and is not empty.Closes #2887
How to test the Change
Changelog Entry
Credits
Props @felipeelia @kovshenin
Checklist: