Summary
WA-VERIFY-083 (PR #1075) identified that Mongoid 8 changes embedded document .count behavior: it now always hits the database rather than using in-memory length. This can cause N+1 queries in code that calls .count on embedded associations.
Approach
# Find .count calls on embedded associations
grep -rn '\.count' app/models/ lib/ --include='*.rb' | grep -v '#.*count'
Audit all .count calls on embedded associations. Where in-memory length is semantically correct (already-loaded array), replace with .size or .length.
Acceptance Criteria
Client Impact
None expected (behavior unchanged; performance may improve).
Related
Summary
WA-VERIFY-083 (PR #1075) identified that Mongoid 8 changes embedded document
.countbehavior: it now always hits the database rather than using in-memory length. This can cause N+1 queries in code that calls.counton embedded associations.Approach
Audit all
.countcalls on embedded associations. Where in-memory length is semantically correct (already-loaded array), replace with.sizeor.length.Acceptance Criteria
.countcalls audited across all models.sizewhere appropriateClient Impact
None expected (behavior unchanged; performance may improve).
Related