Skip to content

Commit 5b53299

Browse files
author
Kit (OpenClaw)
committed
Fix embedded association count calls for Mongoid 8
1 parent 31637a0 commit 5b53299

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 { ... }`).

0 commit comments

Comments
 (0)