Skip to content

fix(member): optimize validation and fix logic order in details update#2475

Merged
olleolleolle merged 1 commit intocodebar:masterfrom
mroderick:fix-member-details-validation-order
Feb 11, 2026
Merged

fix(member): optimize validation and fix logic order in details update#2475
olleolleolle merged 1 commit intocodebar:masterfrom
mroderick:fix-member-details-validation-order

Conversation

@mroderick
Copy link
Collaborator

Problem

The member details update action had a significant performance issue and confusing validation logic:

  • member_params was being called 6+ times per request (severe performance issue)
  • Validation checked original params while controller modified attrs separately
  • Attribute modification happened before validation, creating confusing control flow

Solution

This PR fixes the performance issue and clarifies the logic:

  1. Call member_params once - Store result and reuse throughout the method
  2. Pass attrs to validation - Validation method now accepts attrs parameter instead of calling member_params internally
  3. Validate before modifying - Validate first, then modify attributes for clearer logic flow

Performance Impact

Before: member_params called 6 times per request
After: member_params called 1 time per request

This is a 6x performance improvement for this controller action.

Test Coverage

Added new test validates efficiently by calling member_params only once that:

  • Mocks member_params to track call count
  • Verifies it's called exactly once
  • Documents the performance improvement

All existing tests pass, confirming no regressions.

Changes

  • app/controllers/member/details_controller.rb - Reordered validation and attribute modification
  • app/controllers/concerns/member_concerns.rb - Updated how_you_found_us_selections_valid? to accept attrs parameter
  • spec/controllers/member/details_controller_spec.rb - Added performance regression test

Problem:
- member_params was called 6+ times per request (inefficient)
- Validation was checking original params while attrs were modified
- Confusing control flow made code hard to maintain

Solution:
- Call member_params once and reuse the result
- Pass attrs to validation method instead of re-calling member_params
- Validate BEFORE modifying attributes for clearer logic flow

Performance: Reduced member_params calls from 6 to 1 per request

Test: Added test to verify member_params is called only once
@olleolleolle olleolleolle merged commit 0da0035 into codebar:master Feb 11, 2026
8 checks passed
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.

2 participants