Repository navigation
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.