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

ctrlADel created an issue. See original summary.

a.dmitriiev’s picture

Good point, I think this can be added as a setting in config. I will work on this.

frega’s picture

a.dmitriiev’s picture

Status: Active » Fixed
a.dmitriiev’s picture

Was added as ensure_result_item_url setting, that is TRUE by default for backwards compatibility. Documentation will be changed to encourage users to add url field to index if needed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.