transform_values instead of map+to_h

This commit is contained in:
clemkeirua 2020-09-24 15:11:46 +02:00 committed by Keirua (Rebase PR Action)
parent f3e487bd9e
commit 9b324614b8
2 changed files with 4 additions and 10 deletions

View file

@ -295,8 +295,7 @@ class ProcedurePresentation < ApplicationRecord
def valid_columns_for_table(table)
@column_whitelist ||= fields
.group_by { |field| field['table'] }
.map { |table, fields| [table, Set.new(fields.pluck('column'))] }
.to_h
.transform_values { |fields| Set.new(fields.pluck('column')) }
@column_whitelist[table] || []
end

View file

@ -81,16 +81,12 @@ class AdministrateurUsageStatisticsService
with_default(
0,
nb_dossiers_by_administrateur_id_and_procedure_id_and_synthetic_state[administrateur_id]
.map do |procedure_id, nb_dossiers_by_synthetic_state|
[
procedure_id,
nb_dossiers_by_synthetic_state
.transform_values do |nb_dossiers_by_synthetic_state|
nb_dossiers_by_synthetic_state
.reject { |synthetic_state, _count| ['brouillon', 'archive'].include?(synthetic_state) }
.map { |_synthetic_state, count| count }
.sum
]
end
.to_h
)
end
@ -105,8 +101,7 @@ class AdministrateurUsageStatisticsService
.reject { |procedure_id, _nb_dossiers_by_synthetic_state| is_brouillon(procedure_id) }
.flat_map { |_procedure_id, nb_dossiers_by_synthetic_state| nb_dossiers_by_synthetic_state.to_a }
.group_by { |synthetic_state, _count| synthetic_state }
.map { |synthetic_state, synthetic_states_and_counts| [synthetic_state, synthetic_states_and_counts.map { |_synthetic_state, count| count }.sum] }
.to_h
.transform_values { |synthetic_states_and_counts| synthetic_states_and_counts.map { |_synthetic_state, count| count }.sum }
)
end