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

How to avoid extra sql query for each tweet? #2

Closed
supersexy opened this issue Apr 3, 2020 · 1 comment
Closed

How to avoid extra sql query for each tweet? #2

supersexy opened this issue Apr 3, 2020 · 1 comment

Comments

@supersexy
Copy link

This example code produces one sql extra query for each tweet:

select * from "users" where "users"."id" = '1' limit 1

So for many tweets this will kill any database. I understand that this is just a "basic example", but I would say that avoiding unneccessary db queries belongs to the basic teachings that any new developer should learn - it is really important to not teach people wrong things, they will carry on with that for very long and it will hurt them eventually.

It would be great if you would like to add some information to your tutorial about how to cache queries or avoid them - also it will be a good thing for all the db admins around the world to produce new developers that do not produce code like this :) - thank you very much!

@JeffreyWay
Copy link
Collaborator

Tweet::with('user')->get();

We haven't gotten to the optimization episode yet.

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

No branches or pull requests

2 participants