Move the cached procedure stats queries to a ProcedureStatsConcern
This commit is contained in:
parent
06d60cd943
commit
0c98f29d59
3 changed files with 35 additions and 29 deletions
|
@ -207,9 +207,9 @@ module Instructeurs
|
|||
|
||||
def stats
|
||||
@procedure = procedure
|
||||
@usual_traitement_time = stats_usual_traitement_time(@procedure)
|
||||
@dossiers_funnel = stats_dossiers_funnel(@procedure)
|
||||
@termines_states = stats_termines_states(@procedure)
|
||||
@usual_traitement_time = @procedure.stats_usual_traitement_time
|
||||
@dossiers_funnel = @procedure.stats_dossiers_funnel
|
||||
@termines_states = @procedure.stats_termines_states
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -290,31 +290,5 @@ module Instructeurs
|
|||
end
|
||||
EVAL
|
||||
end
|
||||
|
||||
def stats_usual_traitement_time(procedure)
|
||||
Rails.cache.fetch("#{procedure.cache_key_with_version}/stats_usual_traitement_time", expires_in: 12.hours) do
|
||||
procedure.usual_traitement_time
|
||||
end
|
||||
end
|
||||
def stats_dossiers_funnel(procedure)
|
||||
Rails.cache.fetch("#{procedure.cache_key_with_version}/stats_dossiers_funnel", expires_in: 12.hours) do
|
||||
[
|
||||
['Démarrés', procedure.dossiers.count],
|
||||
['Déposés', procedure.dossiers.state_not_brouillon.count],
|
||||
['Instruction débutée', procedure.dossiers.state_instruction_commencee.count],
|
||||
['Traités', procedure.dossiers.state_termine.count]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def stats_termines_states(procedure)
|
||||
Rails.cache.fetch("#{procedure.cache_key_with_version}/stats_termines_states", expires_in: 12.hours) do
|
||||
[
|
||||
['Acceptés', procedure.dossiers.where(state: :accepte).count],
|
||||
['Refusés', procedure.dossiers.where(state: :refuse).count],
|
||||
['Classés sans suite', procedure.dossiers.where(state: :sans_suite).count]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
30
app/models/concerns/procedure_stats_concern.rb
Normal file
30
app/models/concerns/procedure_stats_concern.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module ProcedureStatsConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def stats_usual_traitement_time
|
||||
Rails.cache.fetch("#{cache_key_with_version}/stats_usual_traitement_time", expires_in: 12.hours) do
|
||||
usual_traitement_time
|
||||
end
|
||||
end
|
||||
|
||||
def stats_dossiers_funnel
|
||||
Rails.cache.fetch("#{cache_key_with_version}/stats_dossiers_funnel", expires_in: 12.hours) do
|
||||
[
|
||||
['Démarrés', dossiers.count],
|
||||
['Déposés', dossiers.state_not_brouillon.count],
|
||||
['Instruction débutée', dossiers.state_instruction_commencee.count],
|
||||
['Traités', dossiers.state_termine.count]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def stats_termines_states
|
||||
Rails.cache.fetch("#{cache_key_with_version}/stats_termines_states", expires_in: 12.hours) do
|
||||
[
|
||||
['Acceptés', dossiers.where(state: :accepte).count],
|
||||
['Refusés', dossiers.where(state: :refuse).count],
|
||||
['Classés sans suite', dossiers.where(state: :sans_suite).count]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,8 @@ require Rails.root.join('lib', 'percentile')
|
|||
class Procedure < ApplicationRecord
|
||||
self.ignored_columns = ['logo', 'logo_secure_token']
|
||||
|
||||
include ProcedureStatsConcern
|
||||
|
||||
MAX_DUREE_CONSERVATION = 36
|
||||
|
||||
has_many :types_de_champ, -> { root.public_only.ordered }, inverse_of: :procedure, dependent: :destroy
|
||||
|
|
Loading…
Reference in a new issue