export cache_key based on column
This commit is contained in:
parent
954d232a47
commit
b5ed8c9b61
4 changed files with 20 additions and 12 deletions
|
@ -81,7 +81,7 @@ class Export < ApplicationRecord
|
|||
export_template:,
|
||||
time_span_type:,
|
||||
statut:,
|
||||
key: generate_cache_key(groupe_instructeurs.map(&:id), procedure_presentation)
|
||||
key: generate_cache_key(groupe_instructeurs.map(&:id), filtered_columns, sorted_column)
|
||||
}
|
||||
|
||||
recent_export = pending
|
||||
|
@ -107,16 +107,13 @@ class Export < ApplicationRecord
|
|||
where(key: generate_cache_key(groupe_instructeurs_ids))
|
||||
end
|
||||
|
||||
def self.generate_cache_key(groupe_instructeurs_ids, procedure_presentation = nil)
|
||||
if procedure_presentation.present?
|
||||
[
|
||||
groupe_instructeurs_ids.sort.join('-'),
|
||||
procedure_presentation.id,
|
||||
Digest::MD5.hexdigest(procedure_presentation.snapshot.slice(:filters, :sort).to_s)
|
||||
].join('--')
|
||||
else
|
||||
groupe_instructeurs_ids.sort.join('-')
|
||||
end
|
||||
def self.generate_cache_key(groupe_instructeurs_ids, filtered_columns = [], sorted_column = nil)
|
||||
columns_key = ([sorted_column] + filtered_columns).compact.map(&:id).sort.join
|
||||
|
||||
[
|
||||
groupe_instructeurs_ids.sort.join('-'),
|
||||
Digest::MD5.hexdigest(columns_key)
|
||||
].join('--')
|
||||
end
|
||||
|
||||
def count
|
||||
|
|
|
@ -23,6 +23,10 @@ class FilteredColumn
|
|||
other&.column == column && other.filter == filter
|
||||
end
|
||||
|
||||
def id
|
||||
column.h_id.merge(filter:).sort.to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_filter_max_length
|
||||
|
|
|
@ -24,4 +24,8 @@ class SortedColumn
|
|||
def sort_by_notifications?
|
||||
@column.notifications? && @order == 'desc'
|
||||
end
|
||||
|
||||
def id
|
||||
column.h_id.merge(order:).sort.to_json
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,10 @@ FactoryBot.define do
|
|||
groupe_instructeurs { [association(:groupe_instructeur)] }
|
||||
|
||||
after(:build) do |export, _evaluator|
|
||||
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation)
|
||||
procedure_presentation = export.procedure_presentation
|
||||
filters = Array.wrap(procedure_presentation&.filters_for(export.statut))
|
||||
sorted_column = procedure_presentation&.sorted_column
|
||||
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), filters, sorted_column)
|
||||
export.user_profile = export.groupe_instructeurs.first&.instructeurs&.first if export.user_profile.nil?
|
||||
export.dossiers_count = 10 if !export.pending?
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue