From 97c50bae0da5d6c0ca1cd53507476762567e7c5c Mon Sep 17 00:00:00 2001 From: mfo Date: Fri, 29 Nov 2024 11:46:12 +0100 Subject: [PATCH] feat(Instructeurs::ProceduresController#show): when an instructeur views list of dossier, caches current loaded page --- .../instructeurs/procedures_controller.rb | 8 ++++++++ app/models/cache/procedure_dossier_pagination.rb | 5 ----- .../instructeurs/procedures_controller_spec.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index df6e11684..d06a3b4fb 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -122,6 +122,8 @@ module Instructeurs .where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id)) .where(seen_at: nil) .distinct + + cache_show_procedure_state # don't move in callback, inherited by Instructeurs::DossiersController end def deleted_dossiers @@ -392,5 +394,11 @@ module Instructeurs def ordered_procedure_ids_params params.require(:ordered_procedure_ids) end + + def cache_show_procedure_state + cache = Cache::ProcedureDossierPagination.new(procedure_presentation:, statut:) + + cache.save_context(ids: @filtered_sorted_paginated_ids, incoming_page: params[:page]) + end end end diff --git a/app/models/cache/procedure_dossier_pagination.rb b/app/models/cache/procedure_dossier_pagination.rb index 0bcee802c..cccd0e6da 100644 --- a/app/models/cache/procedure_dossier_pagination.rb +++ b/app/models/cache/procedure_dossier_pagination.rb @@ -54,11 +54,6 @@ class Cache::ProcedureDossierPagination read_cache[:incoming_page] end - # test only - def raw - read_cache - end - private def cache_key diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 389e849bb..85a0ea9e2 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -670,6 +670,18 @@ describe Instructeurs::ProceduresController, type: :controller do end end end + + describe 'caches statut and page query param' do + let(:statut) { 'tous' } + let(:page) { '1' } + let!(:dossier) { create(:dossier, :accepte, procedure:) } + before { sign_in(instructeur.user) } + subject { get :show, params: { procedure_id: procedure.id, statut:, page: } } + it 'changes cached value' do + expect { subject }.to change { Cache::ProcedureDossierPagination.new(statut:, procedure_presentation: double(procedure:, instructeur:)).send(:read_cache) } + .from({}).to(ids: [dossier.id], incoming_page: page) + end + end end describe '#deleted_dossiers' do