Don't add url to endpoint response

Created on 12 March 2024, 8 months ago
Updated 5 April 2024, 8 months ago

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.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ctrladel North Carolina, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024