cache landing data

This commit is contained in:
simon lehericey 2020-10-06 14:23:15 +02:00
parent ad01d4dee5
commit 4af8bd47ac
5 changed files with 9 additions and 3 deletions

View file

@ -12,6 +12,8 @@ class RootController < ApplicationController
return redirect_to manager_root_path
end
@stat = Stat.first
render 'landing'
end

View file

@ -3,6 +3,7 @@
# Table name: stats
#
# id :bigint not null, primary key
# administrations_partenaires :bigint default(0)
# dossiers_brouillon :bigint default(0)
# dossiers_cumulative :jsonb not null
# dossiers_depose_avant_30_jours :bigint default(0)
@ -30,7 +31,8 @@ class Stat < ApplicationRecord
dossiers_not_brouillon: states['not_brouillon'],
dossiers_termines: states['termines'],
dossiers_cumulative: cumulative_hash(Dossier.state_not_brouillon, :en_construction_at),
dossiers_in_the_last_4_months: last_four_months_hash(Dossier.state_not_brouillon, :en_construction_at)
dossiers_in_the_last_4_months: last_four_months_hash(Dossier.state_not_brouillon, :en_construction_at),
administrations_partenaires: AdministrateursProcedure.joins(:procedure).merge(Procedure.publiees_ou_closes).select('distinct administrateur_id').count
)
end

View file

@ -43,14 +43,14 @@
%ul.numbers
%li.number
.number-value
= number_with_delimiter(AdministrateursProcedure.joins(:procedure).merge(Procedure.publiees_ou_closes).select('distinct administrateur_id').count, :locale => :fr)
= number_with_delimiter(@stat&.administrations_partenaires, :locale => :fr)
.number-label<
administrations
%br<>
partenaires
%li.number
.number-value
= number_with_delimiter(Dossier.state_not_brouillon.count, :locale => :fr)
= number_with_delimiter(@stat&.dossiers_not_brouillon, :locale => :fr)
.number-label<
dossiers
%br<>

View file

@ -8,6 +8,7 @@ class CreateStats < ActiveRecord::Migration[6.0]
t.bigint :dossiers_termines, default: 0
t.bigint :dossiers_depose_avant_30_jours, default: 0
t.bigint :dossiers_deposes_entre_60_et_30_jours, default: 0
t.bigint :administrations_partenaires, default: 0
t.jsonb :dossiers_cumulative, null: false, default: '{}'
t.jsonb :dossiers_in_the_last_4_months, null: false, default: '{}'

View file

@ -594,6 +594,7 @@ ActiveRecord::Schema.define(version: 2020_10_02_124154) do
t.bigint "dossiers_termines", default: 0
t.bigint "dossiers_depose_avant_30_jours", default: 0
t.bigint "dossiers_deposes_entre_60_et_30_jours", default: 0
t.bigint "administrations_partenaires", default: 0
t.jsonb "dossiers_cumulative", default: "{}", null: false
t.jsonb "dossiers_in_the_last_4_months", default: "{}", null: false
t.datetime "created_at", precision: 6, null: false