Skip to content

Fix N+1 #186

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

Merged
merged 1 commit into from
Nov 6, 2017
Merged

Fix N+1 #186

merged 1 commit into from
Nov 6, 2017

Conversation

nalabjp
Copy link
Member

@nalabjp nalabjp commented Nov 6, 2017

N+1が出ていたのでjoins -> includesしました。

@yasulab
Copy link
Member

yasulab commented Nov 6, 2017

LGTM and passed the test suites! Thanks! 😸

@yasulab yasulab merged commit 40010bd into master Nov 6, 2017
@yasulab yasulab deleted the fix-np1 branch November 6, 2017 17:05
@nalabjp
Copy link
Member Author

nalabjp commented Nov 6, 2017

おぉ、すばやい😁
ありがとうございます!

fsbk_dojos = Dojo.joins(:dojo_event_services).where(dojo_event_services: { name: :facebook }).to_a
cnps_dojos = Dojo.includes(:dojo_event_services).where(dojo_event_services: { name: :connpass }).to_a
drkp_dojos = Dojo.includes(:dojo_event_services).where(dojo_event_services: { name: :doorkeeper }).to_a
fsbk_dojos = Dojo.includes(:dojo_event_services).where(dojo_event_services: { name: :facebook }).to_a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoderDojo規模だと問題なさそうですが、このへんincludesだとjoinされるかpreloadされるかわかりづらいので、includes使うのは辞めておいたほうがいいのかもしれません。

過激な意見:

includes を殺して preload か eager_load を強制する cop 転がってないかな

— Takafumi ONAKA (@onk) October 30, 2017

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、ありがとうございます。
直感的に分かるというのはその通りですね。
eager_loadを明示するようにしておきます!

@yasulab yasulab added the 統計情報 Tracking event record function via APIs: https://coderdojo.jp/stats label Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
統計情報 Tracking event record function via APIs: https://coderdojo.jp/stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants