refinerycms-blog icon indicating copy to clipboard operation
refinerycms-blog copied to clipboard

Fix N + 1 for Refinery::Blog::Post.live

Open lanzhiheng opened this issue 6 years ago • 5 comments

Version: refinerycms-blog (4.0.0)

I encounter the N + 1 query when using Refinery::Blog::Post.live

image

Look's good if using Refinery::Blog::Post.includes(:translations).live

image

lanzhiheng avatar Jan 13 '19 06:01 lanzhiheng

Hi @lanzhiheng ! Could you provide a pull request?

bricesanchez avatar Jan 14 '19 14:01 bricesanchez

@bricesanchez I am sorry that I forgot, I will provide a pull request later. 😢

lanzhiheng avatar Jan 14 '19 15:01 lanzhiheng

@bricesanchez Each post's record will need the translation data. so If I avoid the N + 1 query by using includes It will cause a very long query statement. like below

image

I think It is so hard to review by developer. May be the N + 1 version (just using joins) is better than this. I am not sure should I change it to includes? Can you give me some advices?

lanzhiheng avatar Jan 15 '19 14:01 lanzhiheng

Normally I expect joins to produce only a single query; what's the peformance difference you're seeing?

parndt avatar Jan 19 '19 23:01 parndt

@parndt

image

I am not very sure which is better. In my opinion, I expect joins too. 😿 Can you discuss it with @bricesanchez .

lanzhiheng avatar Jan 20 '19 00:01 lanzhiheng