Problem/Motivation
While debugging performance for an endpoint that needs to return ~500 results at once I noticed that the endpoint response helpfully includes each results url if the index response does not include a "url" field. While this seems like a helpful feature it is one that can silently slow down response time. Unless you know to index a url field when using a decoupled endpoint the controller will load each result entity from the database to generate its' url.
if (empty($extracted_fields['url'])) {
$extracted_fields['url'] = $this->getSearchResultUrl($item, $cacheable_metadata);
}
https://git.drupalcode.org/project/search_api_decoupled/-/blob/1.x/src/C...
With ~500 results on my local this is currently adds 60ms to the response time.
Besides the performance impact, there are also situations where an entities canonical page is not accessible to users and should not be exposed to users so having the endpoint automatically add it to the response could be be problematic.
Proposed resolution
Remove, or make optional, adding the url to responses. This prioritizes response speed of the endpoint and I think it is safe to assume that if a url is needed in the response then users will index and configure a url to be returned.
Comments
Comment #2
a.dmitriiev commentedGood point, I think this can be added as a setting in config. I will work on this.
Comment #3
frega commentedFixed in https://git.drupalcode.org/issue/search_api_decoupled-3427443
Comment #4
a.dmitriiev commentedComment #5
a.dmitriiev commentedWas added as
ensure_result_item_urlsetting, that is TRUE by default for backwards compatibility. Documentation will be changed to encourage users to addurlfield to index if needed.