feat(Instructeurs::ProceduresController#show): when an instructeur views list of dossier, caches current loaded page

This commit is contained in:
mfo 2024-11-29 11:46:12 +01:00
parent 1b8db6abee
commit 97c50bae0d
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
3 changed files with 20 additions and 5 deletions

View file

@ -122,6 +122,8 @@ module Instructeurs
.where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id)) .where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id))
.where(seen_at: nil) .where(seen_at: nil)
.distinct .distinct
cache_show_procedure_state # don't move in callback, inherited by Instructeurs::DossiersController
end end
def deleted_dossiers def deleted_dossiers
@ -392,5 +394,11 @@ module Instructeurs
def ordered_procedure_ids_params def ordered_procedure_ids_params
params.require(:ordered_procedure_ids) params.require(:ordered_procedure_ids)
end 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
end end

View file

@ -54,11 +54,6 @@ class Cache::ProcedureDossierPagination
read_cache[:incoming_page] read_cache[:incoming_page]
end end
# test only
def raw
read_cache
end
private private
def cache_key def cache_key

View file

@ -670,6 +670,18 @@ describe Instructeurs::ProceduresController, type: :controller do
end end
end 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 end
describe '#deleted_dossiers' do describe '#deleted_dossiers' do