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

N+1 queries while creating the experiments collection. #18

Open
rocramer opened this issue Aug 12, 2019 · 4 comments
Open

N+1 queries while creating the experiments collection. #18

rocramer opened this issue Aug 12, 2019 · 4 comments
Labels
question Further information is requested

Comments

@rocramer
Copy link

Thanks for the great package, Ben! I noticed N+1 queries:

Example: I created two experiments and two goals. If a user is visiting a page with an included a/b test the package fetches the experiment one, then separately the two goals. After that it fetches the second experiment and the two goals separately as well. Then, it is updating the visitors counter. So in the end 7 queries are performed.

The query problem is due to the nested foreach in the start() method in the ABTesting class. The goals model should be eager loaded.

It would be great if you have a quick solution for the problem. Otherwise I will create a PR in the next weeks.

@ben182
Copy link
Owner

ben182 commented Aug 12, 2019

Hi Robin, thanks for your effort in making this package better. However, I can not confirm the N+1 problem by adding eager loading. In fact by adding eager loading, two additional queries will be executed. Can you confirm this behavior?

@ben182 ben182 added the question Further information is requested label Aug 12, 2019
@rocramer
Copy link
Author

By adding eager loading to the experiment, all associated goals will be fetched via one additional query. In the current implementation, all goals for all experiments are getting fetched separately. See here 19 queries for three experiments and four goals as an example:

Screenshot_2019-08-13 Request Details - Telescope

@adevade
Copy link
Contributor

adevade commented Oct 26, 2019

I can confirm the N+1 on the first page load for a new visitor. If I disable cookies it loads 14 queries every request.

2019-10-26_14-33-46
2019-10-26_14-34-33

@ben182
Copy link
Owner

ben182 commented Nov 17, 2021

Should be fixed through 2.0.2 can somebody confirm?

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

No branches or pull requests

3 participants