mirror of
https://github.com/monoscope-tech/monoscope.git
synced 2026-11-16 10:18:01 +00:00
fix(onboarding): make step completion atomic, and share one implementation
Five sites wrote onboarding_steps_completed, using two strategies that are not
equivalent:
- Log.hs and Monitors.hs open-coded an ATOMIC append:
SET ... = array_append(..., 'x') WHERE id = ? AND NOT ('x' = ANY(...))
- Onboarding.markStepCompleted did a READ-MODIFY-WRITE: take the caller's
already-read vector, append in Haskell, write the whole array back.
The second has a lost-update race — two requests completing *different* steps
both read the same vector, each appends its own, and the second write clobbers
the first's step. So the helper that existed was the racy one, while the correct
form was duplicated inline in two Pages modules.
Now one Projects.completeOnboardingStep with the atomic form. markStepCompleted
delegates and drops its stepsCompleted parameter, so its four call sites no
longer need to have read the project first.
Not touched: Onboarding.hs:256/271 set title/questions in the same statement as
the step, so they need the append folded into that UPDATE rather than a separate
call. Recorded.
Found by grouping all 395 SQL blocks by (operation, table): UPDATE
projects.projects appears 20 times across 4 modules, three of them Pages — which
is what pointed at the layering problem.
This commit is contained in:
parent
6ac599e5fb
commit
b30d874f09
4 changed files with 27 additions and 9 deletions
Loading…
Add table
Add a link
Reference in a new issue