Skip HubSpot deal sync for program-enrolled courses - #3844
Conversation
Add a check in sync_hubspot_deal to skip syncing orders where the purchaser is already enrolled in a program containing the purchased course run. This prevents duplicate/misleading deals in HubSpot when a user buys an individual course that's part of a program they're already enrolled in.
OpenAPI ChangesShow/hide changesUnexpected changes? Ensure your branch is up-to-date with |
for more information, see https://pre-commit.ci
|
|
||
| def _order_is_for_program_enrolled_course(order: Order) -> bool: | ||
| """Return True if any line is a course run belonging to a program the purchaser is already enrolled in.""" | ||
| for line in order.lines.all(): |
There was a problem hiding this comment.
I'm a bit hazy on the data model so forgive me if this is a bad question - generally speaking, how many line items do we expect to have per order?
As written, this could execute up to one query per course run line item. If we do have orders w/ large numbers of line items I'm wondering it's worth iterating through line items to gather the list of CourseRuns from the order and then running a single ProgramEnrollment query for all courses on the order. That'd mean we only do one query regardless of the number of course run line items.
There was a problem hiding this comment.
So I think right now we only support a single line item being added by the user, but we might as well make this efficient like you're saying in case that requirement changes.
Reduce redundant queries when checking whether an order includes a course run from a program the purchaser is already enrolled in. The helper now gathers purchased course IDs first and performs a single `ProgramEnrollment` lookup instead of checking each order line individually.
What are the relevant tickets?
NA
Description (What does it do?)
Add a check in sync_hubspot_deal to skip syncing orders where the purchaser is already enrolled in a program containing the purchased course run. This prevents duplicate/misleading deals in HubSpot when a user buys an individual course that's part of a program they're already enrolled in.
How can this be tested?