Re: [Rails-core] smart eager loading and caching

2014-05-19 Thread Yves Senn
I agree with Matt on this subject. Even if we could come up with useful 
heuristics, we would not deprecate includes, eager_load and preload. There 
are always situations you can't detect. Also I wouldn't want to use that 
feature on some of my apps. It can be crucial what Query is executed and 
such magic code would make it impossible to control.

Cheers,
-- Yves 

On Sunday, May 18, 2014 9:57:05 PM UTC+2, Matt jones wrote:


 On May 16, 2014, at 2:35 PM, Lawrence Wu lawr...@lawrencewu.mejavascript: 
 wrote: 

  I'd like to deprecate methods like includes and eager_load in Rails 
 since I think it is possible to automatically detect when they are needed. 
 Ideally the developer could know very little about how databases work and 
 still get very efficient queries using just the ORM. What do other people 
 think? 

 I’m not terribly convinced that there’s a useful heuristic to 
 automatically make the right choices for eager-loading, since the right 
 associations to load are typically driven by what the code does with the 
 results. 

 For instance, this code fragment should either use something different 
 than `present?` or should use an eager-load, but the right choice depends 
 on what happens after the records are loaded: 

 @posts.each do |post| 
   # present? will cause the comments association to load 
   if post.comments.present? 
 # do something 
 # if post.comments is referenced here, it should have been 
 eager-loaded 
 # if it isn’t referenced, the present? should really be changed to 
 exists? or similar 
   end 
 end 

 Even if such a heuristic existed, it would still be wrong some of the time 
 - so things like `includes` and `eager_load` would still be needed to 
 specify the correct behavior in those cases. 

 It’s definitely worth discussing, but it’s going to (IMO) face a pretty 
 steep climb to success. 

 —Matt Jones 


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Core group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] smart eager loading and caching

2014-05-18 Thread Matt Jones

On May 16, 2014, at 2:35 PM, Lawrence Wu lawre...@lawrencewu.me wrote:

 I'd like to deprecate methods like includes and eager_load in Rails since I 
 think it is possible to automatically detect when they are needed. Ideally 
 the developer could know very little about how databases work and still get 
 very efficient queries using just the ORM. What do other people think?

I’m not terribly convinced that there’s a useful heuristic to automatically 
make the right choices for eager-loading, since the right associations to load 
are typically driven by what the code does with the results.

For instance, this code fragment should either use something different than 
`present?` or should use an eager-load, but the right choice depends on what 
happens after the records are loaded:

@posts.each do |post|
  # present? will cause the comments association to load
  if post.comments.present?
# do something
# if post.comments is referenced here, it should have been eager-loaded
# if it isn’t referenced, the present? should really be changed to exists? 
or similar
  end
end

Even if such a heuristic existed, it would still be wrong some of the time - so 
things like `includes` and `eager_load` would still be needed to specify the 
correct behavior in those cases.

It’s definitely worth discussing, but it’s going to (IMO) face a pretty steep 
climb to success. 

—Matt Jones


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Rails-core] smart eager loading and caching

2014-05-17 Thread richard schneeman
There's a ton of magic in active record as is. If you have ideas on a big 
change like the one you are suggesting, you should fork active record and get 
it working to get feedback. After that it's worth discussing.


If you really want to help here, take a look at open issues tagged with active 
record and see if you can solve them. AR has the most issues open by far.






—
Richard Schneeman

On Sat, May 17, 2014 at 6:38 PM, Lawrence Wu lawre...@lawrencewu.me
wrote:

 I'd like to deprecate methods like includes and eager_load in Rails since I 
 think it is possible to automatically detect when they are needed. Ideally 
 the developer could know very little about how databases work and still get 
 very efficient queries using just the ORM. What do other people think?
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Core group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-core+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-core@googlegroups.com.
 Visit this group at http://groups.google.com/group/rubyonrails-core.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Core group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.