File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # WA-VERIFY-089 / #1080 - Embedded association ` .count ` (Mongoid 8)
2+
3+ Mongoid 8 changed embedded association ` .count ` to always hit the database.
4+ This can introduce unnecessary queries (and N+1s) when the embedded documents
5+ are already loaded in memory.
6+
7+ ## Changes
8+
9+ Replaced embedded-association ` .count ` calls with ` .size ` :
10+
11+ - ` Workarea::OrdersSeeds ` :
12+ - ` user.addresses.count ` → ` user.addresses.size `
13+ - Admin category index:
14+ - ` result.product_rules.count ` → ` result.product_rules.size `
15+ - Admin variants index:
16+ - ` @variants.count ` → ` @variants.size `
17+
18+ ## Intentionally unchanged
19+
20+ - ` .count ` calls on Mongoid criteria/relations (non-embedded) where a database
21+ count is expected.
22+ - ` .count ` on Ruby collections where it is purely in-memory (e.g. arrays/hashes,
23+ or ` Enumerable#count { ... } ` ).
You can’t perform that action at this time.
0 commit comments