generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor amounts calculation (#1188)
# Here be dragons 💀 Time to clean the way we calculate amounts, mere mortal - [x] Kill PfmpAmountCalculator concern (-> `PfmpManager`) 🎯 - [x] Add new API for updating day_count 🎯 - [x] Kill after_save callback for Amount recalculation 🎯 - [x] Add validation on amount not being negative (😮) - [x] Remove state transition on after save too - [x] Add lock on Amounts calculation (prevent possible race) - [x] Encapsulate calculation methods as private methods on the Manager object ## About the removal of after_save callback check Why remove it? Because it sucks, amounts ceilings can be exceeded by spamming requests, rebalancing could happily trigger other rebalancing (the fact that it doesnt currently is pure fluke), highway to **Callback Hell** 👿 and also just to simplify the mental model around this unnecessarily complex process. Replaced by what? A new method on the `PfmpManager` called `update` -> `PfmpManager.new(pfmp).update(day_count: X)` with no side effects other than the one we want which is rebalancing of other pfmps for that same mef. ### Retrocompatibility issues What are the entry points of those callbacks? -> AFAIK: - Pfmp controller update -> replace with new API - Specs trying to check something -> replace with new API - In case of Pfmp destruction -> maybe change condition ### Risks - Not enough tests? - Potential side effects with callbacks of callbacks that might go unnoticed? - Potential negative amounts Pfmps: I reset the ones in the db to 0 (77 records)
- Loading branch information
Showing
13 changed files
with
255 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.