perf(draft_changed?): do not try to compare revisoin if they are not loaded
This commit is contained in:
parent
60800b6113
commit
271ac14fad
2 changed files with 17 additions and 1 deletions
|
@ -439,6 +439,7 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
def draft_changed?
|
||||
preload_draft_and_published_revisions
|
||||
!brouillon? && published_revision.different_from?(draft_revision) && revision_changes.present?
|
||||
end
|
||||
|
||||
|
@ -446,6 +447,15 @@ class Procedure < ApplicationRecord
|
|||
published_revision.compare(draft_revision)
|
||||
end
|
||||
|
||||
def preload_draft_and_published_revisions
|
||||
if !association(:published_revision).loaded? && published_revision_id.present?
|
||||
association(:published_revision).target = ProcedureRevision.includes_for_compare.find(published_revision_id)
|
||||
end
|
||||
if !association(:draft_revision).loaded? && draft_revision_id.present?
|
||||
association(:draft_revision).target = ProcedureRevision.includes_for_compare.find(draft_revision_id)
|
||||
end
|
||||
end
|
||||
|
||||
def accepts_new_dossiers?
|
||||
publiee? || brouillon?
|
||||
end
|
||||
|
|
|
@ -16,7 +16,13 @@ class ProcedureRevision < ApplicationRecord
|
|||
has_one :published_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision
|
||||
|
||||
scope :ordered, -> { order(:created_at) }
|
||||
|
||||
scope :includes_for_compare, -> {
|
||||
includes(revision_types_de_champ: {
|
||||
type_de_champ: { notice_explicative_attachment: :blob, piece_justificative_template_attachment: :blob, revision: [], procedure: [] },
|
||||
revision: [],
|
||||
procedure: []
|
||||
})
|
||||
}
|
||||
validate :conditions_are_valid?
|
||||
validate :header_sections_are_valid?
|
||||
validate :expressions_regulieres_are_valid?
|
||||
|
|
Loading…
Add table
Reference in a new issue