…vious versions of mongoid Signed-off-by: David A. Cuadrado <email@example.com>
- Up to now on this release candidate, all associations when accessed would load and bind their inverses. This caused huge problems when trying to do simple scoped database calls that did not need the objects in memory on large datasets. (Tested with over a million) - Methods affected by this performance drag were #count and any criteria chain off the association itself. - From now on by default relational associations are lazy loaded and will only load into memory and bind when performing array operations on the association that would modify its contents. (<<, push, delete, etc.) - Embedded relations are still eager loaded and bound to their inverses on access. - By providing an :eager => true to the getter or setter for the relation, you can force an eager load into memory. - This commit also fixes all issues with multiple duplicate queries running for the relational associations. From now on, once a query has been executed for the relation, it will never be executed again while the object stays in memory unless a forced reload occurs: person.reload.posts person.posts(true) - This is also a prep commit for the specific eager loading pull request, which will provide the ability to specify an :include to eager load specific associations into memory.
through the relation criteria and hit the database for the exact count. - #count will always hit the db, so the number returned may not actually match the number of documents in memory if for example a related document was persisted by another process. - Use #size or #length for number of docs in memory. - Fixes #542.
child even if provided a persisted parent in the constructor.
- When binding, eager load the relation once for relational associations so that the database query only happens a single time. Otherwise multiple duplicate queries would occur. - Dont set metadata on instantiation of relational associations, defer to loading. - Only embedded relations set metadata on proxy instantiation.