fix open-data endpoint timeout bug #2435
Merged
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.
Changes / Features implemented
Fix the peculiar intermittent bug where after applying pagination on the
GET api/v2/open-data/<uuid>/data
endpoint, the server timeouts if the number of submissions is one but seems to have no problem if the number of submissions is more than 1The fix involves ordering the results only when the queryset returns more than 1 result and only calling the pagination class if the result is more than 1
At the moment, it is not known how applying ordering on the queryset causes the execution to get stuck when getting the first item and not the rest of the items
Other enhancements to optimize the queryset was to make use of only() to ensure we only get the field(s) we are accessing and the use of
Queryset.__len__
instead of count() to count the number of itemsSteps taken to verify this change does what is intended
Side effects of implementing this change
The timeout experienced when pagination is applied for endpoint
GET api/v2/open-data/<uuid>/data
on some occasions should be fixedBefore submitting this PR for review, please make sure you have:
Closes #2436