fix: Optimized goal_reminder_email query - Part 2 - #322
Closed
rahulkanneri-2u wants to merge 5 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes the goal_reminder_email management command to reduce memory usage and pre-filter goals at the database level. An Exists subquery now eliminates CourseGoal rows whose users have no eligible active enrollment, the queryset is streamed via iterator() instead of being fully materialized, and len() calls are replaced with count(). The per-goal timezone check is moved to the start of handle_goal so the cheapest filter runs first, and Site.objects.get_current() is hoisted out of the loop.
Changes:
- Push enrollment eligibility filtering into a DB-level
Existssubquery and stream results withiterator(chunk_size=500)+count()instead oflen(). - Move the timezone window check to the top of
handle_goalto short-circuit early. - Hoist
Site.objects.get_current()out of the per-goal loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Describe what this pull request changes, and why. Include implications for people using this change.
Design decisions and their rationales should be documented in the repo (docstring / ADR), per
OEP-19, and can be
linked here.
Useful information to include:
"Developer", and "Operator".
changes.
Supporting information
Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.
Testing instructions
Please provide detailed step-by-step instructions for testing this change.
Deadline
"None" if there's no rush, or provide a specific date or event (and reason) if there is one.
Other information
Include anything else that will help reviewers and consumers understand the change.