-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance performance of open-data endpoint api/v2/open-data/<uuid>/data
#2456
Conversation
self.data_count = ( | ||
Instance.objects.filter(**qs_kwargs, deleted_at__isnull=True) | ||
.only("pk") | ||
.count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets avoid doing an extra count query and use xform.num_of_submissions
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KipSigei That would work, but we are applying filters so xform.num_of_submissions
will not give us the correct result
use raw SQL queries to improve the performance
we are not using string formatting on raw queries or quote placeholders in the SQL strings as per the Django guidelines
order by is hurting the performance of the SQL query when then number of instances is very large
string interpolation exposes the query to SQL injection
1aa55c4
to
b4db017
Compare
Changes / Features implemented
An improvement to the enhancements implemented here
GET api/v2/open-data/<uuid>/data
id
in ascending order since when the number of submissions is large the query is extremely slow. There is also no reason to order the results by default. The consumers of the endpoint can carry out that functionality by themselvesSteps taken to verify this change does what is intended
Side effects of implementing this change
Faster response times for endpoint
GET api/v2/open-data/<uuid>/data
Before submitting this PR for review, please make sure you have:
Closes #