neon
neon

Reputation: 2821

Ways to Increase Rails 3 Performance

BACKGROUND: I have a list of posts that need to be sorted their 'votes' and then show the top 50 posts.

OBJECTIVE: I am currently using .take(50) to accomplish this, as using .limit(50) or .first(50) show the first 50 posts UNSORTED.

Using .take makes the app unusually slow, are there any alternatives to this method?

Upvotes: 0

Views: 480

Answers (1)

drewrobb
drewrobb

Reputation: 1604

You can combine limit and order clauses using something like:

Post.all(:order => "votes", :limit => 50)

This generates SQL that only selected 50 Posts, but ordered.

Upvotes: 3

Related Questions