Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sctor suggestions method is very very slow with candidates.delete_at rand(candidates.size) #482

Open
leopoldchen opened this issue Jul 14, 2014 · 0 comments

Comments

@leopoldchen
Copy link

When there were thousands of users for suggestion, this method seems like cost 2-3 second. Then I google how to get random records by sql in rails, here is the result I got:

  Model.first(:order => "RANDOM()") # postgres example

In this way, the solution could be

 candidates = candidates.order("RANDOM()").limit(size)

This will more faster then the original code.

But different database get different rand function. See detail in this url:
http://www.petefreitag.com/item/466.cfm
I don't know how many kinds of database SocialStream need to support. With a support list, it might could optimize it with a method to get current random func for current database.

Anyway, for somebody who got this problem, could just use the decorator to rewrite this method.

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

No branches or pull requests

1 participant