LoginSignup
0
0

More than 3 years have passed since last update.

膨大なデータの処理が予想されるとき、SQLでその処理を済ませた方がパフォーマンスを維持できる

Posted at

言いたいこと

膨大なデータの処理が予想されるとき、SQLでその処理を済ませた方がパフォーマンスを維持できる

クラウドファウンディングサイトを例にしてみる

目的:パトロンをたくさん持っているプロダクトから降順で表示したい

この場合、controller上でデータを取り出し計算する方法と、取り出した時点ですでに計算されている状態にする方法の二択が考えられる。もちろん後者の方がいい。


products = self.joins(:patrons).group(:product_id).select('count(patrons.product_id) as patron_count').order('patron_count desc')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0