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
Summer Workshop Pre Survey #33278
Summer Workshop Pre Survey #33278
Conversation
…workshop_pre_survey merge in latest changes.
dashboard/app/controllers/pd/workshop_daily_survey_controller.rb
Outdated
Show resolved
Hide resolved
if form_name | ||
# if any submission has the given form name return true, otherwise return false | ||
submissions.each {|submission| return true if submission.foorm_submission.form_name == form_name} | ||
return false |
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.
Nit: Unless there's eager loading going on, I think .foorm_submission
is a query in a loop here.
I think you could modify your search before it runs and achieve a similar effect with one query. Something like (and apologies, not sure I've got this right):
submissions = Pd::WorkshopSurveyFoormSubmission.where(
user_id: user_id,
pd_workshop_id: pd_workshop_id,
pd_session_id: pd_session_id,
day: day
)
if form_name
submissions = submissions.join(:foorm_submission).where(foorm_submission: {form_name: form_name})
end
submissions.exists?
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.
Also, not sure if things still feel too prototype-y to you, but this business logic is a great candidate for a unit test.
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.
fixed! your syntax was very close, only difference is .where(foorm_submissions...)
Will do tests in follow-up PR
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.
Love the factoring on this. What an impactful change!
Foorm work building on 33182, which adds some generic functionality as well as new foorm survey for the local summer workshop pre-survey ('day 0' survey)
New generic functionality:
new_general_foorm
which directs to Foorm.jsxLocal Summer Workshop functionality:
/pd/workshop_survey/foorm/day/0
(any other day parameter will show a 404 since we don't have a new survey for those days yet).