Merge pull request #9696 from colinux/procedure-visible-by-user-faster
Perf: accélération du chargement des dossiers visibles
This commit is contained in:
commit
7fca13d02c
7 changed files with 18 additions and 7 deletions
|
@ -223,7 +223,7 @@ class Dossier < ApplicationRecord
|
|||
scope :prefilled, -> { where(prefilled: true) }
|
||||
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
|
||||
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
|
||||
scope :visible_by_user, -> { where(for_procedure_preview: false).or(where(for_procedure_preview: nil)).where(hidden_by_user_at: nil, editing_fork_origin_id: nil) }
|
||||
scope :visible_by_user, -> { where(for_procedure_preview: false).where(hidden_by_user_at: nil, editing_fork_origin_id: nil) }
|
||||
scope :visible_by_administration, -> {
|
||||
state_not_brouillon
|
||||
.where(hidden_by_administration_at: nil)
|
||||
|
|
|
@ -709,7 +709,7 @@ class Procedure < ApplicationRecord
|
|||
close!
|
||||
end
|
||||
|
||||
dossiers.visible_by_administration.each do |dossier|
|
||||
dossiers.visible_by_administration.find_each do |dossier|
|
||||
dossier.hide_and_keep_track!(author, :procedure_removed)
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class Stat < ApplicationRecord
|
|||
COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state = 'brouillon' AND editing_fork_origin_id IS NULL AND (for_procedure_preview IS NULL OR for_procedure_preview = false)) AS "brouillon",
|
||||
COUNT(*) FILTER ( WHERE state = 'brouillon' AND editing_fork_origin_id IS NULL AND for_procedure_preview = false) AS "brouillon",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction",
|
||||
COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AlterDossiersForProcedurePreviewNotNullable < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_check_constraint :dossiers, "for_procedure_preview IS NOT NULL", name: "dossiers_for_procedure_preview_null", validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class ValidateAlterDossiersForProcedurePreviewNotNullable < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
validate_check_constraint :dossiers, name: "dossiers_for_procedure_preview_null"
|
||||
change_column_null :dossiers, :for_procedure_preview, false, false
|
||||
remove_check_constraint :dossiers, name: "dossiers_for_procedure_preview_null"
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_11_07_150217) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_11_10_135533) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -402,7 +402,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_07_150217) do
|
|||
t.datetime "en_construction_at", precision: 6
|
||||
t.datetime "en_construction_close_to_expiration_notice_sent_at", precision: 6
|
||||
t.datetime "en_instruction_at", precision: 6
|
||||
t.boolean "for_procedure_preview", default: false
|
||||
t.boolean "for_procedure_preview", default: false, null: false
|
||||
t.boolean "forced_groupe_instructeur", default: false, null: false
|
||||
t.bigint "groupe_instructeur_id"
|
||||
t.datetime "groupe_instructeur_updated_at", precision: 6
|
||||
|
|
|
@ -27,7 +27,6 @@ describe Stat, type: :model do
|
|||
create_list(:dossier, 2, :en_construction, depose_at: 10.days.ago, procedure:)
|
||||
create_list(:dossier, 3, :en_construction, depose_at: 40.days.ago, procedure:)
|
||||
|
||||
create_list(:dossier, 3, :brouillon, procedure:, for_procedure_preview: nil)
|
||||
create_list(:dossier, 1, :brouillon, procedure:, for_procedure_preview: false)
|
||||
|
||||
create_list(:dossier, 6, :en_instruction, procedure:)
|
||||
|
@ -48,7 +47,7 @@ describe Stat, type: :model do
|
|||
expect(stats["not_brouillon"]).to eq(18)
|
||||
expect(stats["dossiers_depose_avant_30_jours"]).to eq(2)
|
||||
expect(stats["dossiers_deposes_entre_60_et_30_jours"]).to eq(3)
|
||||
expect(stats["brouillon"]).to eq(4)
|
||||
expect(stats["brouillon"]).to eq(1)
|
||||
expect(stats["en_construction"]).to eq(5)
|
||||
expect(stats["en_instruction"]).to eq(6)
|
||||
expect(stats["termines"]).to eq(7)
|
||||
|
|
Loading…
Reference in a new issue