refactor(badges): prevent orphaned BadgeProgress creation#2989
refactor(badges): prevent orphaned BadgeProgress creation#2989luisfelipec95 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @luisfelipec95! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Description
The badge processing system is creating an excessive number of orphaned
BadgeProgressrecords (records without associatedFulfillmentdata) due to a critical logic flaw. With 140+ active badge templates, this issue is significantly amplified, creating thousands of unnecessary database records daily.Changes
An optional
createparameter (default True) was added to thefor_user()method. This parameter controls whether the method should create a new BadgeProgress record when it doesn't exist, or simply retrieve it if it already exists.Previously, the method always created a record using
get_or_create(), with no option to just query. This meant any code that called this method, even just to check if a record existed, would end up automatically creating one.How to test
Configure Badge Template:
org.openedx.learning.course.passing.status.updated.v1org.openedx.learning.ccx.course.passing.status.updated.v1Create Badge Requirements:
is_passing = true)Create a test course in Studio:
Enroll test student in course
Before the changes
At the time of testing, there are 8 active badge templates, of which only 4 meet the rules for a completed course, yet 8 badgeProgress records are generated.
After the changes
It only creates in badgeProgress the necessary records—those that meet the badge template rules.