feat(procedure_presentation): pass filters as serialized snapshot
This commit is contained in:
parent
e82dc9c8b5
commit
9904dabffe
4 changed files with 34 additions and 11 deletions
|
@ -2,14 +2,15 @@
|
|||
#
|
||||
# Table name: exports
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# format :string not null
|
||||
# key :text not null
|
||||
# statut :string default("tous")
|
||||
# time_span_type :string default("everything"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# procedure_presentation_id :bigint
|
||||
# id :bigint not null, primary key
|
||||
# format :string not null
|
||||
# key :text not null
|
||||
# procedure_presentation_snapshot :jsonb
|
||||
# statut :string default("tous")
|
||||
# time_span_type :string default("everything"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# procedure_presentation_id :bigint
|
||||
#
|
||||
class Export < ApplicationRecord
|
||||
MAX_DUREE_CONSERVATION_EXPORT = 3.hours
|
||||
|
@ -60,6 +61,8 @@ class Export < ApplicationRecord
|
|||
end
|
||||
|
||||
def compute
|
||||
load_snapshot!
|
||||
|
||||
file.attach(
|
||||
io: io,
|
||||
filename: filename,
|
||||
|
@ -78,7 +81,11 @@ class Export < ApplicationRecord
|
|||
end
|
||||
|
||||
def old?
|
||||
updated_at < 20.minutes.ago
|
||||
updated_at < 20.minutes.ago || filters_changed?
|
||||
end
|
||||
|
||||
def filters_changed?
|
||||
procedure_presentation&.snapshot != procedure_presentation_snapshot
|
||||
end
|
||||
|
||||
def filtered?
|
||||
|
@ -98,7 +105,7 @@ class Export < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.find_or_create_export(format, groupe_instructeurs, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs, procedure_presentation: procedure_presentation)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs, procedure_presentation: procedure_presentation, procedure_presentation_snapshot: procedure_presentation&.snapshot)
|
||||
.includes(:procedure_presentation)
|
||||
.create_or_find_by(format: format,
|
||||
time_span_type: time_span_type,
|
||||
|
@ -147,6 +154,12 @@ class Export < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def load_snapshot!
|
||||
if procedure_presentation_snapshot.present?
|
||||
procedure_presentation.attributes = procedure_presentation_snapshot
|
||||
end
|
||||
end
|
||||
|
||||
def dossiers_for_export
|
||||
@dossiers_for_export ||= begin
|
||||
dossiers = Dossier.where(groupe_instructeur: groupe_instructeurs)
|
||||
|
|
|
@ -263,6 +263,10 @@ class ProcedurePresentation < ApplicationRecord
|
|||
})
|
||||
end
|
||||
|
||||
def snapshot
|
||||
slice(:filters, :sort, :displayed_fields)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def field_id(field)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddProcedurePresentationSnapshotToExports < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :exports, :procedure_presentation_snapshot, :jsonb
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_04_05_110354) do
|
||||
ActiveRecord::Schema.define(version: 2022_04_05_163206) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -432,6 +432,7 @@ ActiveRecord::Schema.define(version: 2022_04_05_110354) do
|
|||
t.string "format", null: false
|
||||
t.text "key", null: false
|
||||
t.bigint "procedure_presentation_id"
|
||||
t.jsonb "procedure_presentation_snapshot"
|
||||
t.string "statut", default: "tous"
|
||||
t.string "time_span_type", default: "everything", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
|
Loading…
Reference in a new issue