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
Link enrollment to application in workshop view #33615
Conversation
33b4187
to
6348ac3
Compare
# @param [Integer] workshop_id | ||
# @return [Integer, nil] application id or nil if cannot find any application | ||
def find_application_id(user_id, workshop_id) | ||
Pd::Application::ApplicationBase.where(user_id: user_id).each do |application| |
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.
is there a reason you can't search on user id and application id together?
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.
I think it's because pd_application_id
is not a column in our database, but a serialized property inside the JSON properties
column for this application record. We can probably use MySQL 5 JSON features for this, but ActiveRecord won't do it for us.
I was wondering if you can use Pd::Application::TeacherApplicationBase
here, which provides pd_workshop_id
so you don't need the try
below. I'm curious to see if/how that modifies the generated query here.
A bigger perf concern, for me, is that using this method and the enrollment serializer is introducing a query-per-enrollment for a workshop page load, which might be a performance issue for very large workshops. We probably don't need to overthink this yet, but let's keep an eye on this feature - if the workshop detail view noticeably slows down, we probably want to pull this logic out to the controller and look up all applications for all enrollments in one query. (Or figure out a change to our data model that makes this less painful.)
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 fact, thinking on this a little more, it does feel like pd_application_id
really ought to be a column on enrollment, not a serialized property, with an ActiveRecord association defined.
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.
To play devil's advocate, the only time we care about associating an enrollment with an application is in the case of a teacher enrolling in a 5-day (CSP/D) summer workshop, right? That's a really small (albeit important) fraction of the overall number of enrollments, so it'd be like 95% null.
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.
Brad's explanation is correct. pd_application_id
is a property in property bag, which is saved as a string data type in pd_applications table.
Using TeacherApplicationBase
instead of ApplicationBase
will not search the entire pd_applications table. It will default to type = TeacherApplicationBase. pd_applications is 1 table shared by multiple models (Single Table Inheritance).
I'll add a JIRA task with potential workarounds Brad and I discussed.
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.
@bencodeorg: Agree, the number of of enrollments can be mapped to applications is small. The problem is when you open a workshop view, it will grab all enrollments for that workshop in 1 query. However, for each enrollment, we then make 1 more query to pd_applications table to get matching application_id (no matter if it exists or not). If there is 100 enrollments in a workshop, it will create a total of 101 queries instead of 1. This could be a potential performance issue.
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.
Jira task created: https://codedotorg.atlassian.net/browse/PLC-809
apps/src/code-studio/pd/workshop_dashboard/components/workshop_enrollment_school_info.jsx
Outdated
Show resolved
Hide resolved
apps/src/code-studio/pd/workshop_dashboard/components/workshop_enrollment_school_info.jsx
Outdated
Show resolved
Hide resolved
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.
Absolute url (production-only) is blocking.
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.
👍 I think we can ship this, and follow up with iterations on the UX or performance if necessary. Thanks Ha!
In the workshop view, add links from enrollments to the corresponding applications. This feature only works for CSD and CSP workshops. (CSF workshop doesn't require applications.)
Before
After
Links
Testing story
Reviewer Checklist: