Merge pull request #9916 from colinux/fix-admin-zones-n1
Perf ETQ admin: supprime plusieurs requêtes inutiles / page
This commit is contained in:
commit
1d0f5966f9
4 changed files with 22 additions and 2 deletions
|
@ -139,7 +139,7 @@ class Administrateur < ApplicationRecord
|
|||
end
|
||||
|
||||
def zones
|
||||
procedures.joins(:zones).flat_map(&:zones).uniq
|
||||
procedures.includes(:zones).flat_map(&:zones).uniq
|
||||
end
|
||||
|
||||
# required to display feature flags field in manager
|
||||
|
|
|
@ -5,6 +5,9 @@ class ProceduresFilter
|
|||
|
||||
def initialize(admin, params)
|
||||
@admin = admin
|
||||
|
||||
params[:zone_ids] = admin.zones.pluck(:id) if params[:zone_ids] == 'admin_default'
|
||||
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, tags: [], zone_ids: [], statuses: [])
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
%ul.fr-nav__list
|
||||
%li.fr-nav__item= link_to 'Mes démarches', admin_procedures_path, class:'fr-nav__link', 'aria-current': current_page?(controller: 'administrateurs/procedures', action: :index) ? 'page' : nil
|
||||
- if Rails.application.config.ds_zonage_enabled
|
||||
%li.fr-nav__item= link_to 'Toutes les démarches', all_admin_procedures_path(zone_ids: current_administrateur.zones), class:'fr-nav__link', 'aria-current': current_page?(all_admin_procedures_path) ? 'page' : nil
|
||||
%li.fr-nav__item= link_to 'Toutes les démarches', all_admin_procedures_path(zone_ids: :admin_default), class:'fr-nav__link', 'aria-current': current_page?(all_admin_procedures_path) ? 'page' : nil
|
||||
- if current_administrateur.groupe_gestionnaire_id
|
||||
%li.fr-nav__item= link_to 'Mon groupe gestionnaire', admin_groupe_gestionnaire_path, class:'fr-nav__link', 'aria-current': current_page?(admin_groupe_gestionnaire_path) ? 'page' : nil
|
||||
|
||||
|
|
|
@ -116,6 +116,23 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
expect(assigns(:procedures).any? { |p| p.id == draft_procedure.id }).to be_falsey
|
||||
end
|
||||
|
||||
context 'for default admin zones' do
|
||||
let(:zone1) { create(:zone) }
|
||||
let(:zone2) { create(:zone) }
|
||||
let!(:procedure1) { create(:procedure, :published, zones: [zone1]) }
|
||||
let!(:procedure2) { create(:procedure, :published, zones: [zone1, zone2]) }
|
||||
let!(:admin_procedure) { create(:procedure, :published, zones: [zone2], administrateur: admin) }
|
||||
|
||||
subject { get :all, params: { zone_ids: :admin_default } }
|
||||
|
||||
it 'display only procedures for specified zones' do
|
||||
subject
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_truthy
|
||||
expect(assigns(:procedures).any? { |p| p.id == admin_procedure.id }).to be_truthy
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure1.id }).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "for specific zones" do
|
||||
let(:zone1) { create(:zone) }
|
||||
let(:zone2) { create(:zone) }
|
||||
|
|
Loading…
Reference in a new issue