Skip to content
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

Merged
merged 5 commits into from Mar 13, 2020
Merged

Conversation

hacodeorg
Copy link
Contributor

@hacodeorg hacodeorg commented Mar 13, 2020

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
Screen Shot 2020-03-13 at 12 11 33 AM

After
Screen Shot 2020-03-13 at 12 40 42 PM

Links

Testing story

  • Unit tested
  • Manually tested
    include FactoryGirl::Syntax::Methods
    csd = create :csd_academic_year_workshop
    csp = create :csp_summer_workshop
    u = create :teacher
    csda = create :pd_teacher2021_application, user: u, pd_workshop_id: csd.id
    cspa = create :pd_teacher1920_application, user: u, pd_workshop_id: csp.id
    
    csde = create :pd_enrollment, user: u, workshop: csd
    cspe = create :pd_enrollment, user: u, workshop: csp
    
    # Then go to these pages to verify links show up correctly
    "http://localhost-studio.code.org:3000/pd/workshop_dashboard/workshops/#{csd.id}"
    "http://localhost-studio.code.org:3000/pd/workshop_dashboard/workshops/#{csp.id}"

Reviewer Checklist:

  • Tests provide adequate coverage
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@hacodeorg hacodeorg changed the title Link enrollment to application in workshop dashboard Link enrollment to application in workshop view Mar 13, 2020
@hacodeorg hacodeorg requested a review from a team March 13, 2020 07:36
@hacodeorg hacodeorg marked this pull request as ready for review March 13, 2020 07:36
# @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|
Copy link
Contributor

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?

Copy link
Contributor

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.)

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@islemaster islemaster left a 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.

Copy link
Contributor

@islemaster islemaster left a 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!

@hacodeorg hacodeorg merged commit fbe0b57 into staging Mar 13, 2020
@hacodeorg hacodeorg deleted the ha/ws-link-to-app branch March 13, 2020 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants