Ruby on Rails Saturday, July 27, 2013

On Saturday, July 27, 2013 4:22:26 AM UTC+1, marcin longlastname wrote:

So instead, it seems I have to order the entire table first, then pluck, and then getting the last few rows. This seems extremely inefficient since I have to order all rows of it first, even though I am specifically using pluck over select for performance and memory reasons. Does anyone have any suggestions or ideas for a higher performance method of getting the a specific column of the last few rows of a table ordered by the primary key? I also extremely reccomend mentioning in the pluck API documentation that pluck returns an un-ordered list so others do not fall into the same mistake I did.

 Timed.asset.order('id desc').limit(10).pluck(:id)

In general if you haven't specified an order then no order is applied. First is an exception rather than the rule here.

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/73c5de19-3dc8-4d59-b628-050722f3656d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment