-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ETQ Usager, je veux qu'on supprime mon brouillon après 3 mois d'inactivité (correction) #11145
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11145 +/- ##
===========================================
- Coverage 84.41% 55.93% -28.49%
===========================================
Files 1200 1198 -2
Lines 26380 29657 +3277
Branches 4965 4350 -615
===========================================
- Hits 22269 16588 -5681
- Misses 4111 13069 +8958 ☔ View full report in Codecov by Sentry. |
ee58fa4
to
7546723
Compare
b5ed9f6
to
c40dd53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classe et pas si compliqué finalement !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le code me semble bon, par sécurité j'ai tenté de jouer la requete en prod :
avant:
Dossier.brouillon_close_to_expiration.count
=> 36075
apres:
class Dossier < ApplicationRecord
scope :interval_brouillon_close_to_expiration, -> do
max_months = 3
state_brouillon
.visible_by_user
.where("dossiers.updated_at + dossiers.conservation_extension + (LEAST(procedures.duree_conservation_dossiers_dans_ds, #{max_months}) * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end
Dossier.brouillon_close_to_expiration.count
=> 1464588
Que penses-tu de lisser ça dans le temps en capant avec un max par jour ex: avec un max à 50k, ça permet de lisser ca sur 28 jours (sinon on va tuer nos quota).
J'imagine que ca peut se passer dans app/services/expired/dossiers_deletion_service.rb
, p-e en ajoutant un limit(ENV['TO_BE_DEFINED'])
si la mm var d'env est presenté ?
spec/system/users/brouillon_spec.rb
Outdated
login_as(user, scope: :user) | ||
visit brouillon_dossier_path(user_old_dossier) | ||
|
||
expect(page).to have_css('.fr-callout__title', text: 'Votre dossier a expiré', visible: true) | ||
find('#test-user-repousser-expiration').click | ||
expect(page).to have_no_selector('#test-user-repousser-expiration') | ||
|
||
Timecop.freeze(simple_procedure.duree_conservation_dossiers_dans_ds.month.from_now) do | ||
travel_to((9.months + 1.day).from_now) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
il est étrange ce 9.months + 1.day, ça aurait été un peu plus comprehensible ac : simple_procedure.duree_conservation_dossiers_dans_ds.month.from_now
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouais c'est difficilement compréhensible, en fait c'est 3 (expiration initiale) + 6 (expiration prolongée) mois. je vais rendre ça plus explicite.
app/models/dossier.rb
Outdated
state_brouillon | ||
.visible_by_user | ||
.where("dossiers.updated_at + dossiers.conservation_extension + (LEAST(procedures.duree_conservation_dossiers_dans_ds, 3) * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) | ||
.where("dossiers.updated_at + dossiers.conservation_extension + (LEAST(procedures.duree_conservation_dossiers_dans_ds, #{max_months}) * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ce max_months ne serait t'il pas le même que Expired::MONTHS_BEFORE_BROUILLON_EXPIRATION ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bien vu !
Oui après discussion avec Bouchra on peut même descendre à 10K dans un premier temps pour s'assurer que le support ne se fait pas déborder |
user_notifications = group_by_user_email(dossiers_close_to_expiration) | ||
|
||
dossiers_close_to_expiration.in_batches.update_all(brouillon_close_to_expiration_notice_sent_at: Time.zone.now) | ||
user_notifications = group_by_user_email(dossiers_close_to_expiration).take(MAX_BROUILLON_DELETION_EMAILS_TO_PROCESS_PER_DAY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'avais un doute le .take
qui implique de charger/traiter les 1.4M de records, j'ai testé sur la prod : pas de timeout, par contre mon process c'est fait Killed, j'imagine on se prend un OOM.
Un petit limit
haut dessus et je pense qu'on est bon.
…brouillon close to expiration using `limit` instead of `take` for perf reasons
…n close to expiration windows due to limit which could skip some
1586d81
to
9c19adf
Compare
…llon_close_to_expiration_notice_sent_at
…brouillon_close_to_expiration_notice_sent_at reset
…m this controller
fix #10951
Un mécanisme de suppression de brouillon existait déjà, j'ai donc retiré le code ajouté en doublon récemment et modifié le comportement déjà en place pour prendre en compte les nouvelles exigences (suppression 3 mois à partir de la dernière MAJ)