Skip to content

Optimize assorted Django operations#627

Closed
aviupadhyayula wants to merge 17 commits into
masterfrom
optimize-orm
Closed

Optimize assorted Django operations#627
aviupadhyayula wants to merge 17 commits into
masterfrom
optimize-orm

Conversation

@aviupadhyayula

@aviupadhyayula aviupadhyayula commented Mar 10, 2024

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented Mar 10, 2024

Copy link
Copy Markdown

Codecov Report

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

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

Files with missing lines 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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread backend/clubs/management/commands/update_club_counts.py
@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
@aviupadhyayula

Copy link
Copy Markdown
Member Author

This is stale and most of these changes have been obviated by platform and dependency upgrades. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants