8000 Add capacity limits for Huddlz by mwoods79 · Pull Request #124 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

Add capacity limits for Huddlz - #124

Merged
mwoods79 merged 10 commits into
mainfrom
codex/add-huddl-capacity-limits
Apr 30, 2026
Merged

mwoods79 merged 10 commits into
mainfrom
codex/add-huddl-capacity-limits

Conversation

@mwoods79
Copy link
Copy Markdown
Contributor

Summary

  • Add optional max_attendees support to Huddlz with migration and Ash snapshot
  • Enforce capacity during RSVP with a row lock to avoid overbooking
  • Show capacity status/progress in Huddl detail and card UI, including Event Full state
  • Prevent organizers from reducing capacity below current RSVP count

Closes #15

Follow-up

Tests

  • mix format
  • git diff --check
  • mix test test/huddlz/communities/huddl_rsvp_test.exs test/huddlz_web/live/huddl_live/show_test.exs test/huddlz_web/live/huddl_live/new_test.exs test/huddlz_web/live/huddl_live/edit_test.exs

Note: full mix test currently has one unrelated existing failure in test/huddlz_web/live/huddl_live/new_image_upload_test.exs around Unicode slug redirect encoding.

mwoods79 added 10 commits April 29, 2026 21:51
- Replace raw SQL FOR UPDATE / count with Ash.Query.lock and Ash.count!
- Drop Ecto.UUID.dump!, Repo, and Ecto.Adapters.SQL aliases
- Restructure existing-rsvp check so the predicate has no side effects;
  the action transaction handles rollback via changeset errors
Convert the CapacityNotBelowRsvps validation into a Change attached to
the :update action. The change locks the huddl row with FOR UPDATE
before counting attendees, eliminating the TOCTOU race where an
organizer could shrink capacity while a member RSVP was in flight.

- Add Huddlz.Communities.Huddl.Changes.EnforceCapacityFloor
- Wire it into the :update action only (was previously a global
  validation gated in code on action.name)
- Delete the now-unused validation module
The five capacity helpers (event_full?, capacity_label, capacity_percent,
capacity_status, capacity_status_class) were duplicated verbatim in
HuddlLive.Show and CommunityComponents. Promote the helpers in
CommunityComponents from defp to def — they're auto-imported into every
LiveView via HuddlzWeb html_helpers — and drop the duplicates from Show.
- Unlimited huddl (max_attendees nil) accepts arbitrary RSVPs
- :create accepts and enforces max_attendees end to end
- Edit form renders inline error when reducing capacity below current RSVPs
- New form sets max_attendees and the show page renders "0/N spots filled"
- Card empty-state shows the capacity label, status, and 0% progress bar
Both Changes locked the huddl row and then issued a separate
COUNT(*) query against HuddlAttendee. The Huddl resource already
exposes an :rsvp_count aggregate, which composes with FOR UPDATE.
Loading it on the locked read replaces the second query with the
same one — and lets at_capacity? read the count off the struct
instead of taking a redundant huddl_id arg through the call chain.
The card duplicated the "<icon> <capacity_label>" span across two
branches of an outer if. Collapse to a single span guarded by
max_attendees || rsvp_count > 0; the inner if/else still picks
between capacity_label and the legacy "X attending" copy.
capacity_status and capacity_status_class were mirrored cond chains
that each recomputed event_full? and capacity_percent. Extract a
private capacity_tier/1 returning an atom; both helpers now match
on the tier instead of evaluating the thresholds twice per render.
- "Almost full" tier (4/5 = 80%) was untested; only :full,
  :filling_up, and :plenty had coverage.
- Clearing max_attendees to nil with existing RSVPs was untested;
  EnforceCapacityFloor's nil short-circuit had no guard against
  regression.
- The card-with-RSVPs path of the flattened capacity row was
  untested; only the rsvp_count = 0 case had a search test.
@mwoods79
mwoods79 merged commit bce4534 into main Apr 30, 2026
1 check passed
@mwoods79
mwoods79 deleted the codex/add-huddl-capacity-limits branch April 30, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Capacity Limits for Huddlz

1 participant

0