From dd1dd974abbc437342d6127bc1237a7a498a310e Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:13:43 +0100 Subject: [PATCH] Performance (#810) * Setup subsection is always enabled * Cache setup subsection page generation * Cache setup section page question generation --- app/models/form/setup/pages/created_by.rb | 3 +-- app/models/form/setup/pages/location.rb | 3 +-- app/models/form/setup/pages/needs_type.rb | 3 +-- app/models/form/setup/pages/organisation.rb | 3 +-- app/models/form/setup/pages/property_reference.rb | 3 +-- app/models/form/setup/pages/renewal.rb | 3 +-- app/models/form/setup/pages/rent_type.rb | 3 +-- app/models/form/setup/pages/scheme.rb | 3 +-- app/models/form/setup/pages/tenancy_start_date.rb | 3 +-- app/models/form/setup/pages/tenant_code.rb | 3 +-- app/models/form/setup/subsections/setup.rb | 7 +++++-- 11 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/models/form/setup/pages/created_by.rb b/app/models/form/setup/pages/created_by.rb index a32741eab..edaa43fff 100644 --- a/app/models/form/setup/pages/created_by.rb +++ b/app/models/form/setup/pages/created_by.rb @@ -4,12 +4,11 @@ class Form::Setup::Pages::CreatedBy < ::Form::Page @id = "created_by" @header = "" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::CreatedById.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/location.rb b/app/models/form/setup/pages/location.rb index 5b22df634..4a86c9a9a 100644 --- a/app/models/form/setup/pages/location.rb +++ b/app/models/form/setup/pages/location.rb @@ -3,7 +3,6 @@ class Form::Setup::Pages::Location < ::Form::Page super("location", hsh, subsection) @header = "" @description = "" - @questions = questions @depends_on = [{ "supported_housing_schemes_enabled?" => true, "needstype" => 2, @@ -12,7 +11,7 @@ class Form::Setup::Pages::Location < ::Form::Page end def questions - [ + @questions ||= [ Form::Setup::Questions::LocationId.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/needs_type.rb b/app/models/form/setup/pages/needs_type.rb index f1c78e1f1..0db6ef1c2 100644 --- a/app/models/form/setup/pages/needs_type.rb +++ b/app/models/form/setup/pages/needs_type.rb @@ -4,13 +4,12 @@ class Form::Setup::Pages::NeedsType < ::Form::Page @id = "needs_type" @header = "" @description = "" - @questions = questions @depends_on = [{ "supported_housing_schemes_enabled?" => true }] @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::NeedsType.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/organisation.rb b/app/models/form/setup/pages/organisation.rb index 011d010ed..166bc2181 100644 --- a/app/models/form/setup/pages/organisation.rb +++ b/app/models/form/setup/pages/organisation.rb @@ -4,12 +4,11 @@ class Form::Setup::Pages::Organisation < ::Form::Page @id = "organisation" @header = "" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::OwningOrganisationId.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/property_reference.rb b/app/models/form/setup/pages/property_reference.rb index 0314816c8..14fafade2 100644 --- a/app/models/form/setup/pages/property_reference.rb +++ b/app/models/form/setup/pages/property_reference.rb @@ -4,12 +4,11 @@ class Form::Setup::Pages::PropertyReference < ::Form::Page @id = "property_reference" @header = "" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::PropertyReference.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/renewal.rb b/app/models/form/setup/pages/renewal.rb index 959a1d94f..8a627d7c9 100644 --- a/app/models/form/setup/pages/renewal.rb +++ b/app/models/form/setup/pages/renewal.rb @@ -4,12 +4,11 @@ class Form::Setup::Pages::Renewal < ::Form::Page @id = "renewal" @header = "" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::Renewal.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/rent_type.rb b/app/models/form/setup/pages/rent_type.rb index 317fa0e0c..9c927c9af 100644 --- a/app/models/form/setup/pages/rent_type.rb +++ b/app/models/form/setup/pages/rent_type.rb @@ -3,13 +3,12 @@ class Form::Setup::Pages::RentType < ::Form::Page super("rent_type", hsh, subsection) @header = "" @description = "" - @questions = questions @depends_on = [{ "supported_housing_schemes_enabled?" => true }] @derived = true end def questions - [ + @questions ||= [ Form::Setup::Questions::RentType.new(nil, nil, self), Form::Setup::Questions::IrproductOther.new(nil, nil, self), ] diff --git a/app/models/form/setup/pages/scheme.rb b/app/models/form/setup/pages/scheme.rb index b60d07964..2b9cc5dbf 100644 --- a/app/models/form/setup/pages/scheme.rb +++ b/app/models/form/setup/pages/scheme.rb @@ -3,7 +3,6 @@ class Form::Setup::Pages::Scheme < ::Form::Page super("scheme", hsh, subsection) @header = "" @description = "" - @questions = questions @depends_on = [{ "supported_housing_schemes_enabled?" => true, "needstype" => 2, @@ -11,7 +10,7 @@ class Form::Setup::Pages::Scheme < ::Form::Page end def questions - [ + @questions ||= [ Form::Setup::Questions::SchemeId.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/tenancy_start_date.rb b/app/models/form/setup/pages/tenancy_start_date.rb index be1f24ca9..117ef8452 100644 --- a/app/models/form/setup/pages/tenancy_start_date.rb +++ b/app/models/form/setup/pages/tenancy_start_date.rb @@ -3,12 +3,11 @@ class Form::Setup::Pages::TenancyStartDate < ::Form::Page super @id = "tenancy_start_date" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::TenancyStartDate.new(nil, nil, self), ] end diff --git a/app/models/form/setup/pages/tenant_code.rb b/app/models/form/setup/pages/tenant_code.rb index aa2b7e5c9..f7b8350d1 100644 --- a/app/models/form/setup/pages/tenant_code.rb +++ b/app/models/form/setup/pages/tenant_code.rb @@ -4,12 +4,11 @@ class Form::Setup::Pages::TenantCode < ::Form::Page @id = "tenant_code" @header = "" @description = "" - @questions = questions @subsection = subsection end def questions - [ + @questions ||= [ Form::Setup::Questions::TenantCode.new(nil, nil, self), ] end diff --git a/app/models/form/setup/subsections/setup.rb b/app/models/form/setup/subsections/setup.rb index 0f481af6b..1db76986d 100644 --- a/app/models/form/setup/subsections/setup.rb +++ b/app/models/form/setup/subsections/setup.rb @@ -3,12 +3,11 @@ class Form::Subsections::Setup < ::Form::Subsection super @id = "setup" @label = "Set up this lettings log" - @pages = [pages] @section = section end def pages - [ + @pages ||= [ Form::Setup::Pages::Organisation.new(nil, nil, self), Form::Setup::Pages::CreatedBy.new(nil, nil, self), Form::Setup::Pages::NeedsType.new(nil, nil, self), @@ -26,6 +25,10 @@ class Form::Subsections::Setup < ::Form::Subsection questions.select { |q| support_only_questions.include?(q.id) } + super end + def enabled?(_case_log) + true + end + private def support_only_questions