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

Optimize assorted Django operations #627

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

aviupadhyayula
Copy link
Member

@aviupadhyayula aviupadhyayula commented Mar 10, 2024

Meant to generally optimize our usage of the Django ORM, with a focus on taking full advantage of major upgrades in #605.

Changelog:

  • Use subqueries to update membership & favorite counts in update_club_counts. Shows a ~70% speedup in local benchmarks (n=2000 memberships/favorites).
  • Use bulk updates when updating decision reasons for application submissions.
  • Use bulk create when creating activities fairs for registered clubs.
    • Concerned with how bulk_create plays with AutoField primary keys (like we have for the Events model). But, the documentation mentions that pSQL should be fine.[1]
    • I'm assuming the order of the returned Events objects doesn't matter. Would appreciate a second set of eyes.
  • Use qs.exists() to check existence instead of qs.first() is not None whenever possible.
  • Avoid fetching objects from DB into memory whenever possible.

[1] https://docs.djangoproject.com/en/5.0/ref/models/querysets/#bulk-create

Copy link

codecov bot commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 48.85496% with 67 lines in your changes are missing coverage. Please review.

Project coverage is 69.29%. Comparing base (813cd4b) to head (c5a912d).
Report is 20 commits behind head on master.

Files Patch % Lines
backend/clubs/views.py 44.82% 64 Missing ⚠️
...nd/clubs/management/commands/update_club_counts.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #627      +/-   ##
==========================================
+ Coverage   69.11%   69.29%   +0.17%     
==========================================
  Files          30       30              
  Lines        6362     6353       -9     
==========================================
+ Hits         4397     4402       +5     
+ Misses       1965     1951      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aviupadhyayula aviupadhyayula marked this pull request as ready for review April 2, 2024 00:28
@aviupadhyayula aviupadhyayula requested a review from rm03 April 2, 2024 00:28
@aviupadhyayula aviupadhyayula changed the title Optimize Django operations Optimize assorted Django operations Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants