Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

SEL for count? #11

Open
solnic opened this issue May 17, 2011 · 4 comments
Open

SEL for count? #11

solnic opened this issue May 17, 2011 · 4 comments

Comments

@solnic
Copy link
Contributor

solnic commented May 17, 2011

Associations seem to be eager-loading when all that is required is a count. This can take awhile when the count of rows is even in the 10k+ area, if not more.

http://gist.github.com/156762


Created by Tony Pitale - 2009-07-27 22:00:09 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/992

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

First stab at a dm-aggregates failing spec patch. Not sure it can be made to pass from within dm-aggregates.

by Tony Pitale

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

The problem may be with DataMapper::Collection#delegate_to_relationship which does not create a lazyarray or something like it. At that point, it fully builds the collection from the relationship before anything (e.g., count) is ever done to it. It would seem that the only time we would actually want to load something when we want to do something with it.

by Tony Pitale

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

This is probably not news to anyone but me, however, SEL is used regardless of whether or not the association in a loop is ever used for anything. That’s obviously an affect of the association not being a lazyarray when called.

by Tony Pitale

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

Here is a potential change to dm-core that fixes my original gist. It changes the spec and Collection to lazy load for #delegate_to_relationship. This ends up breaking the many_to_many spec in a way I have yet to understand, but I will post up anyway.

by Tony Pitale

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant