Skip to content

[api] Fix candidates endpoints timeout for very large projects - #11347

Open
driusan wants to merge 1 commit into
aces:mainfrom
driusan:BigCandidate
Open

driusan wants to merge 1 commit into
aces:mainfrom
driusan:BigCandidate

Conversation

@driusan

@driusan driusan commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

The API candidates endpoint can exhaust all the memory for large projects, as it converts every candidate to an array, which it then converts to a JSON string, which it then hashes in order to calculate the ETag.

The array representation (or array + JSON string) held in memory can exceed the php.ini memory limits if there are a large number of candidates.

This replaces the ETag on the candidates endpoint which is currently calculated by hashing the JSON response to an ETag calculated by a hash of the latest timestamp on the candidates table and the count of entries in the candidates table.

However, the array itself can still exceed the server's memory. A new IterableStream PSR7 StreamInterface is added which takes an Iterator and directly streams it while read to prevent the whole database query being loaded into memory at once. An optional "objectkey" parameter can be provided to an IterableStream to return an object of the form "{ objectkey: [...] }" instead of "[...]" to maintain compatibility with the API.

Tested with 175447 randomly generated candidates.

The API candidates endpoint can exhaust all the memory for large projects,
as it converts every candidate to an array, which it then converts to
a JSON string, which it then hashes in order to calculate the ETag.

The array representation (or array + JSON string) held in memory can exceed
the php.ini memory limits if there are a large number of candidates.

This replaces the ETag on the candidates endpoint which is currently
calculated by hashing the JSON response to an ETag calculated by
a hash of the latest timestamp on the candidates table and the count
of entries in the candidates table.

However, the array itself can still exceed the server's memory. A new
IterableStream PSR7 StreamInterface is added which takes an Iterator and
directly streams it while read to prevent the whole database query being
loaded into memory at once. An optional "objectkey" parameter can be provided
to an IterableStream to return an object of the form "{ objectkey: [...] }"
instead of "[...]" to maintain compatibility with the API.

Tested with 175447 randomly generated candidates.
@github-actions github-actions Bot added Language: PHP PR or issue that update PHP code Module: api PR or issue related to api module labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Language: PHP PR or issue that update PHP code Module: api PR or issue related to api module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant