From a711288d5d85a1e81e0474c968dcf0092e51af8c Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 18 Sep 2025 10:41:26 +0100 Subject: [PATCH] Ensure cache invalidation happens This fixes a number of places where the cache for the counts in the header weren't being invalidated meaning they would end up with the incorrect value. Jira-Issue: MAV-2004 --- app/controllers/consent_forms_controller.rb | 8 ++++++++ app/controllers/imports/issues_controller.rb | 3 ++- app/forms/import_duplicate_form.rb | 8 +++++++- app/forms/school_move_form.rb | 6 ++++++ .../features/import_child_records_with_duplicates_spec.rb | 3 +++ spec/features/parental_consent_clinic_spec.rb | 1 + spec/features/parental_consent_manual_matching_spec.rb | 2 ++ 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/controllers/consent_forms_controller.rb b/app/controllers/consent_forms_controller.rb index 6f50912688..167b7a412a 100644 --- a/app/controllers/consent_forms_controller.rb +++ b/app/controllers/consent_forms_controller.rb @@ -35,6 +35,8 @@ def edit_match def update_match @consent_form.match_with_patient!(@patient, current_user:) + reset_count! + session = @patient .sessions @@ -109,6 +111,8 @@ def create_patient school_move.confirm! @consent_form.match_with_patient!(patient, current_user:) + + reset_count! end if patient.nhs_number.nil? @@ -144,4 +148,8 @@ def set_patient def archive_params params.expect(consent_form: :notes).merge(archived_at: Time.current) end + + def reset_count! + TeamCachedCounts.new(current_team).reset_unmatched_consent_responses! + end end diff --git a/app/controllers/imports/issues_controller.rb b/app/controllers/imports/issues_controller.rb index 684ba85de6..1b3760c2c8 100644 --- a/app/controllers/imports/issues_controller.rb +++ b/app/controllers/imports/issues_controller.rb @@ -70,7 +70,8 @@ def set_patient def set_form apply_changes = params.dig(:import_duplicate_form, :apply_changes) - @form = ImportDuplicateForm.new(object: @record, apply_changes:) + @form = + ImportDuplicateForm.new(current_team:, object: @record, apply_changes:) end def set_type diff --git a/app/forms/import_duplicate_form.rb b/app/forms/import_duplicate_form.rb index 4c50d4eb67..842eb857ce 100644 --- a/app/forms/import_duplicate_form.rb +++ b/app/forms/import_duplicate_form.rb @@ -3,7 +3,7 @@ class ImportDuplicateForm include ActiveModel::Model - attr_accessor :object, :apply_changes + attr_accessor :current_team, :object, :apply_changes validates :apply_changes, inclusion: { in: :apply_changes_options } @@ -21,6 +21,8 @@ def save end end + reset_count! + true rescue ActiveRecord::RecordInvalid errors.add(:base, "Failed to save changes") @@ -51,4 +53,8 @@ def discard_pending_changes! def keep_both_changes! object.apply_pending_changes_to_new_record! if can_keep_both? end + + def reset_count! + TeamCachedCounts.new(current_team).reset_import_issues! + end end diff --git a/app/forms/school_move_form.rb b/app/forms/school_move_form.rb index 8e299d92fd..cf7ec50dba 100644 --- a/app/forms/school_move_form.rb +++ b/app/forms/school_move_form.rb @@ -20,6 +20,12 @@ def save @school_move.ignore! end + TeamCachedCounts.new(team).reset_school_moves! + true end + + private + + def team = current_user.selected_team end diff --git a/spec/features/import_child_records_with_duplicates_spec.rb b/spec/features/import_child_records_with_duplicates_spec.rb index 43bc61db44..b2b46e80f5 100644 --- a/spec/features/import_child_records_with_duplicates_spec.rb +++ b/spec/features/import_child_records_with_duplicates_spec.rb @@ -242,6 +242,7 @@ def and_i_upload_a_file_with_duplicate_records end def then_i_should_see_the_import_page_with_duplicate_records + expect(page).to have_content("Imports (3)") expect(page).to have_content( "3 records have import issues to resolve before they can be imported into Mavis" ) @@ -364,11 +365,13 @@ def when_i_go_to_the_import_page end def then_i_should_see_import_issues_with_the_count + expect(page).to have_content("Imports (1)") expect(page).to have_link("Import issues") expect(page).to have_selector(".app-count", text: "(1)") end def then_i_should_see_no_import_issues_with_the_count + expect(page).to have_content("Imports (0)") expect(page).to have_link("Import issues") expect(page).to have_selector(".app-count", text: "(0)") end diff --git a/spec/features/parental_consent_clinic_spec.rb b/spec/features/parental_consent_clinic_spec.rb index 783ac5c4c9..6eb1ba7b86 100644 --- a/spec/features/parental_consent_clinic_spec.rb +++ b/spec/features/parental_consent_clinic_spec.rb @@ -256,6 +256,7 @@ def and_the_nurse_confirms_the_move choose "Update record with new school" click_on "Update child record" expect(page).to have_content("Success") + expect(page).to have_content("School moves (0)") end def then_the_nurse_should_see_no_moves diff --git a/spec/features/parental_consent_manual_matching_spec.rb b/spec/features/parental_consent_manual_matching_spec.rb index c57cc52762..bf00765385 100644 --- a/spec/features/parental_consent_manual_matching_spec.rb +++ b/spec/features/parental_consent_manual_matching_spec.rb @@ -91,6 +91,7 @@ def given_the_patient_has_aged_out_of_the_programme def when_i_go_to_the_dashboard sign_in @user visit dashboard_path + expect(page).to have_content("Unmatched responses (1)") end def and_i_click_on_unmatched_consent_responses @@ -135,6 +136,7 @@ def then_i_can_review_the_match def when_i_link_the_response_with_the_record click_on "Link response with record" + expect(page).to have_content("Unmatched responses (0)") end def and_i_click_on_the_patient