Skip to content

WA-VERIFY-089: Fix embedded document count behavior change in Mongoid 8 #1080

@kitcommerce

Description

@kitcommerce

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

  • Embedded association .count calls audited across all models
  • In-memory count calls changed to .size where appropriate
  • No performance regressions (N+1 queries introduced)
  • Notes file documents the audit findings and changes

Client Impact

None expected (behavior unchanged; performance may improve).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions