Commit 5f1a503
committed
fix: make join enrollment idempotent under concurrent requests
Wraps role and class-membership creation in a transaction, switches the
check-then-create pattern to find_or_create_by!, and rescues
ActiveRecord::RecordNotUnique so that two simultaneous POSTs to
/api/join/:join_code for the same user no longer surface a 500 when
the DB unique index catches a race that the in-memory existence
checks missed.1 parent 348efe2 commit 5f1a503
1 file changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
101 | 106 | | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
| 112 | + | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
0 commit comments