Optimize notifications queries for badges by using exists?, not present?

`ActiveRecord::Relation.exists?` yields a SQL EXISTS query, while `present?` is a method of Enumerable, which needs the actual result array to be queried.
This commit is contained in:
Nicolas Bouilleaud 2019-09-20 12:42:10 +02:00 committed by simon lehericey
parent a4166d3c57
commit 1505d45be1

View file

@ -24,13 +24,13 @@
instructeur_procedure_path(@procedure, statut: 'suivis'),
active: @statut == 'suivis',
badge: @followed_dossiers.count,
notification: current_instructeur.notifications_for_procedure(@procedure, :en_cours).present?)
notification: current_instructeur.notifications_for_procedure(@procedure, :en_cours).exists?)
= tab_item(t('pluralize.processed', count: @termines_dossiers.count),
instructeur_procedure_path(@procedure, statut: 'traites'),
active: @statut == 'traites',
badge: @termines_dossiers.count,
notification: current_instructeur.notifications_for_procedure(@procedure, :termine).present?)
notification: current_instructeur.notifications_for_procedure(@procedure, :termine).exists?)
= tab_item('tous les dossiers',
instructeur_procedure_path(@procedure, statut: 'tous'),