Skip to content
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

Query optimization for the Briefcase viewset #2142

Merged
merged 6 commits into from
Oct 6, 2021
Merged

Conversation

DavisRayM
Copy link
Contributor

@DavisRayM DavisRayM commented Sep 7, 2021

Changes / Features implemented

  • Utilize XForm num_of_submissions instead of trying to count all the instances when numEntries is not specified
    • Count instances using len() instead of count() to avoid an additional Database query & preload the instances before the render
  • Only retrieve the pk & uuid columns from the database instead of all the instance table columns; The briefcase viewset does not utilize any of the other columns

Steps taken to verify this change does what is intended

  • N/A

Side effects of implementing this change

Improved performance on the briefcase viewset. Performance gain

  • Decreased no. of queries for requests with numEntries query param:
  • Decreased no. of queries for requests with the numEntries query param:

Tests were done on a form with 4601 submissions

With changes & numEntries query param

Screenshot from 2021-09-16 14-00-29

Without changes & numEntries query param

Screenshot from 2021-09-16 14-05-16

With changes & No query param

Screenshot from 2021-09-16 15-01-48

Without changes & No query param

Screenshot from 2021-09-16 15-03-07

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Closes #

@DavisRayM DavisRayM force-pushed the briefcase-changes branch 2 times, most recently from 489a4a6 to 2b4efe0 Compare September 14, 2021 09:11
@DavisRayM DavisRayM changed the title [WIP] Optimize Briefcase viewset counts Minor optimization for the Briefcase viewset Sep 14, 2021
Avoid multiple calls to `.count()` which case the application to
re-query the database
Minor optimization for the `SELECT` query as we do not utilize any of
the other columns within the instance table in the BriefcaseViewSet
…ueryset

Not using the `num_of_submissions` attribute since it counts submissions
which have not yet received all media files yet.
@DavisRayM DavisRayM changed the title Minor optimization for the Briefcase viewset Query optimization for the Briefcase viewset Oct 5, 2021
deleted_at__isnull=True)
instances = Instance.objects.filter(
xform=xform, deleted_at__isnull=True).values(
'pk', 'uuid')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using the uuid anywhere? We could just only return the pk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, forgot about that.

deleted_at__isnull=True)
instances = Instance.objects.filter(
xform=xform, deleted_at__isnull=True).values(
'pk', 'uuid')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, forgot about that.

@DavisRayM DavisRayM merged commit ee9c156 into master Oct 6, 2021
@DavisRayM DavisRayM deleted the briefcase-changes branch October 6, 2021 13:13
@DavisRayM DavisRayM mentioned this pull request Oct 7, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants