-
Notifications
You must be signed in to change notification settings - Fork 3
Add best_run_id to REST/search API results #2696
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
Conversation
OpenAPI ChangesShow/hide 208 changes: 0 error, 0 warning, 208 infoUnexpected changes? Ensure your branch is up-to-date with |
| def best_run(self) -> Optional["LearningResourceRun"]: | ||
| """Returns the most current/upcoming enrollable run for the learning resource""" | ||
| published_runs = self.runs.filter(published=True) | ||
| if hasattr(self, "_published_runs"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inclusion of best_run_id in the serializer introduced lots of n+1 query errors, which is why this property needed to be refactored.
0f4a863 to
396d00d
Compare
shanbady
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving 👍 refactoring here looks good and worked as described.
There are two corner cases which are good to be aware of but probably warrants a separate discussion+PR:
- Our contentfile loader has a bunch of logic that tries to pick a "best run" - currently seems to just grab the first published run which is potentially causing issues
- We have these "test_mode" courses which may not have any published runs but should still fallback to something (maybe the first run with contentfiles if it has multiple unpublished runs)
|
I will create a separate issue for the 2 things you mentioned above, I don't think they should be addressed in this PR. |
396d00d to
5280d25
Compare
learning_resources/models.py
Outdated
| # If no current enrollable run found, find the next upcoming run | ||
| upcoming_runs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past, I've understood "published" to mean "enrollable". Is that no longer true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never was - all OCW courses are published but not enrollable for example, You can access all the course material but there is no enrollment possible. Ditto for OpenLearningLibrary,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't OCW and OLL be included in enrollable_runs array via this filter?
not run.enrollment_start
and run.start_date
and run.start_date <= now
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, run.start_date is always None for OCW and OLL
learning_resources/models.py
Outdated
| if upcoming_runs: | ||
| return min(upcoming_runs, key=lambda r: r.start_date) | ||
|
|
||
| # If current_run is still null, return the run with the latest start date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_run ... typo?
learning_resources/models.py
Outdated
| # If no current enrollable run found, find the next upcoming run | ||
| upcoming_runs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't OCW and OLL be included in enrollable_runs array via this filter?
not run.enrollment_start
and run.start_date
and run.start_date <= now
)
542ba39 to
7365408
Compare
What are the relevant tickets?
Backend part of https://github.com/mitodl/hq/issues/9206
Description (What does it do?)
best_run_idfield to learning resource serializers and search indexHow can this be tested?
./manage.py recreate_index --all./manage.py backpopulate_ocw_data --course-name 7-05-general-biochemistry-spring-2020best_run_idequal to the id of the course's one run.best_run_idvalue equal to the id of thebest_run.When this gets to RC/production, the search index will need to be recreated to include the new
best_run_idfield.