Browse Source

Perf (#592)

* Memoize start year

* Reset

* Recalculate rather than reset
pull/596/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
858fe6f705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/case_log.rb

9
app/models/case_log.rb

@ -22,6 +22,7 @@ class CaseLog < ApplicationRecord
has_paper_trail
validates_with CaseLogValidator
before_validation :recalculate_start_year!, if: :startdate_changed?
before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :reset_invalidated_dependent_fields!
@ -66,10 +67,16 @@ class CaseLog < ApplicationRecord
end
def collection_start_year
return @start_year if @start_year
return unless startdate
window_end_date = Time.zone.local(startdate.year, 4, 1)
startdate < window_end_date ? startdate.year - 1 : startdate.year
@start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year
end
def recalculate_start_year!
@start_year = nil
collection_start_year
end
def form_name

Loading…
Cancel
Save