2
說我有100,000條推文。如何使用活動記錄非常有效地選擇一個Tweet?什麼是使用Active Record選擇一個隨機記錄的最有效方式
Tweet.all => [100K Records]
I want => Tweet.find_by_id[random] (something like this)
說我有100,000條推文。如何使用活動記錄非常有效地選擇一個Tweet?什麼是使用Active Record選擇一個隨機記錄的最有效方式
Tweet.all => [100K Records]
I want => Tweet.find_by_id[random] (something like this)
我會避免選擇全部,只是建立隨機到你的查詢,像這樣:
Tweet.find(:first, :order => "RAND()")
您可以使用此
Tweet.first(:order => "RAND()")
你比傑德更多的風格 – eggie5