Commit 75ecc09
committed
fix: deduplicate members in chapter_students and chapter_coaches
Members subscribed to multiple groups within a chapter were being
processed multiple times when sending invitations with audience='everyone',
causing 'Member has already been taken' validation errors.
Root Cause:
- Member.in_group() uses JOIN on subscriptions, returning duplicate rows
when a member is subscribed to the same group type multiple times
- 336 members in London chapter affected (subscribed to both Students and Coaches)
- 35 members in Berlin chapter affected
- 57 members in Brighton chapter affected
Impact:
- Workshop invitation batches failed mid-process (e.g., 517 of 7000+
invitations sent before failure)
- InvitationLogEntry validates uniqueness of member_id per invitation,
causing validation errors on second processing attempt
- Admins had to manually retry batch sends multiple times
Affected Chapters:
- 46 of 54 chapters (85%) have members with duplicate subscriptions
- ~1,200 members affected across all chapters
- Top 5: London (336), West London (79), Brighton (57), South London (57),
Barcelona (55), Edinburgh (37), Berlin (35)
Timeline:
- Original code (Jan 2017, commit 448acc7) included .uniq for deduplication
- Refactoring (May 2018, commit d7a463d) extracted to scopes but
accidentally removed the .uniq call
Fix: Add .distinct to chapter_students and chapter_coaches methods,
restoring the deduplication behavior that existed before the refactoring.
Tests:
- Add spec for unique members when subscribed to same group multiple times
- Add spec for unique invitations per role when member is in both groups1 parent c788c7b commit 75ecc09
File tree
2 files changed
+71
-2
lines changed- app/models
- spec/models
2 files changed
+71
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
0 commit comments