Cache requests in procedures/stats
This commit is contained in:
parent
3e2985b305
commit
06d60cd943
1 changed files with 29 additions and 14 deletions
|
@ -207,20 +207,9 @@ module Instructeurs
|
|||
|
||||
def stats
|
||||
@procedure = procedure
|
||||
@usual_traitement_time = procedure.usual_traitement_time
|
||||
|
||||
@dossiers_funnel = [
|
||||
['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]
|
||||
]
|
||||
|
||||
@termines_states = [
|
||||
['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]
|
||||
]
|
||||
@usual_traitement_time = stats_usual_traitement_time(@procedure)
|
||||
@dossiers_funnel = stats_dossiers_funnel(@procedure)
|
||||
@termines_states = stats_termines_states(@procedure)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -301,5 +290,31 @@ 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
|
||||
|
|
Loading…
Reference in a new issue