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

Fixes issue with bad join in Phase load #901

Merged
merged 1 commit into from
Dec 6, 2017

Conversation

briri
Copy link
Contributor

@briri briri commented Dec 5, 2017

rewrote Plans.load_for_phase query
We discovered that the join from the old query was not considering the plan when retrieving answers. This resulted in a query that returned - (question * ([all answers from any plan]). The page logic was only displaying the correct records but the query itself was causing significant page load times. Here is the query:

FROM `plans` 
  LEFT OUTER JOIN `templates` ON `templates`.`id` = `plans`.`template_id` 
  LEFT OUTER JOIN `phases` ON `phases`.`template_id` = `templates`.`id` 
  LEFT OUTER JOIN `sections` ON `sections`.`phase_id` = `phases`.`id` 
  LEFT OUTER JOIN `questions` ON `questions`.`section_id` = `sections`.`id` 
  LEFT OUTER JOIN `answers` ON `answers`.`question_id` = `questions`.`id` AND `answers`.`plan_id` = `plans`.`id` 
  LEFT OUTER JOIN `notes` ON `notes`.`answer_id` = `answers`.`id` 
  LEFT OUTER JOIN `annotations` ON `annotations`.`question_id` = `questions`.`id` 
  LEFT OUTER JOIN `question_formats` ON `question_formats`.`id` = `questions`.`question_format_id` 
  LEFT OUTER JOIN `questions_themes` ON `questions_themes`.`question_id` = `questions`.`id` 
  LEFT OUTER JOIN `themes` ON `themes`.`id` = `questions_themes`.`theme_id` 
  LEFT OUTER JOIN `templates` `customizations_templates` ON `customizations_templates`.`dmptemplate_id` = `templates`.`id` 
  LEFT OUTER JOIN `orgs` ON `orgs`.`id` = `customizations_templates`.`org_id` 
  LEFT OUTER JOIN `orgs` `orgs_templates` ON `orgs_templates`.`id` = `templates`.`org_id` 
  LEFT OUTER JOIN `plans_guidance_groups` ON `plans_guidance_groups`.`plan_id` = `plans`.`id` 
  LEFT OUTER JOIN `guidance_groups` ON `guidance_groups`.`id` = `plans_guidance_groups`.`guidance_group_id` 
  LEFT OUTER JOIN `guidances` ON `guidances`.`guidance_group_id` = `guidance_groups`.`id` 
  LEFT OUTER JOIN `themes_in_guidance` ON `themes_in_guidance`.`guidance_id` = `guidances`.`id` 
  LEFT OUTER JOIN `themes` `themes_guidances` ON `themes_guidances`.`id` = `themes_in_guidance`.`theme_id`
WHERE `plans`.`id` = 1234 AND `phases`.`id` = 123 AND `plans`.`id` IN (1234)

After further review it was also discovered that it was unnecessary to load the guidance_groups and associated guidance in this query since the controller loads it again afterward via the Plan.guidance_groups method

rewrote Plans.load_for_phase query

added notes to new query
@jollopre
Copy link
Contributor

jollopre commented Dec 6, 2017

Good caught! Note that any note within the entire db was also retrieved...

@jollopre jollopre merged commit 900c59d into DMPRoadmap:CDL-MVP Dec 6, 2017
@briri briri deleted the phase-load-bug branch December 13, 2017 16:38
briri added a commit that referenced this pull request Jan 22, 2018
Cherry-pick of bugfix from PR #901 for deployment on live service
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.

2 participants