Description
In app/models/account.rb, several methods iterate through domains using .each loops:
host() (line 66-79) calls domains.length then primary_custom_domain which iterates again
unverified_domain?() (line 134-139) iterates all domains
apex_domain() (line 91-95) iterates all domains
primary_custom_domain() iterates all domains
These are called on every page load via redirect_if_host_changed.
Recommendation
- Use
domains.exists?(verified: false) for unverified_domain?
- Use
domains.find_by(redirect_for_name: [nil, '']) for primary_custom_domain
- Cache domain lookups or eager-load domains where needed
Severity
Medium