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

Tidy up queries in dashboard #398

Closed
krzysztofrewak opened this issue Feb 21, 2024 · 1 comment · Fixed by #409
Closed

Tidy up queries in dashboard #398

krzysztofrewak opened this issue Feb 21, 2024 · 1 comment · Fixed by #409
Labels
investigation things to research php Pull requests that update Php code

Comments

@krzysztofrewak
Copy link
Member

I was playing with local Toby and I noticed that (at least for my example) dashboard generates almost 100 database queries.

Query
96 queries, 54 of which are duplicated. 	Duration
64.21ms

I believe some of these could be replaces with proper eager loading or other forms of optimization:

select * from "profiles" where "profiles"."user_id" in (1) 	0.35ms 	
select * from "profiles" where "profiles"."user_id" in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15... 	0.75ms 	
select * from "profiles" where "profiles"."user_id" in (1, 2, 4, 5, 6, 7, 8, 9, 10) 	0.37ms 	
select * from "profiles" where "profiles"."user_id" in (10) 	0.24ms 	
select * from "profiles" where "profiles"."user_id" in (10) 	0.76ms 	
select * from "profiles" where "profiles"."user_id" in (3) 	0.28ms 	
select * from "profiles" where "profiles"."user_id" in (3) 	0.36ms 	
select * from "profiles" where "profiles"."user_id" in (3, 4, 8) 	0.43ms 	
select * from "profiles" where "profiles"."user_id" in (4) 	0.25ms 	
select * from "profiles" where "profiles"."user_id" in (4) 	0.36ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.24ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.24ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.24ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.25ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.25ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.26ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.28ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.38ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.38ms 	
select * from "profiles" where "profiles"."user_id" in (8) 	0.41ms 	

select * from "users" where "users"."id" = 10 limit 1 	0.26ms 	
select * from "users" where "users"."id" = 3 limit 1 	0.37ms 	
select * from "users" where "users"."id" = 3 limit 1 	0.37ms 	
select * from "users" where "users"."id" = 4 limit 1 	0.35ms 	
select * from "users" where "users"."id" = 4 limit 1 	0.41ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.25ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.25ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.26ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.26ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.26ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.27ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.32ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.34ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.38ms 	
select * from "users" where "users"."id" = 8 limit 1 	0.42ms 	

select * from "vacations" where "vacations"."vacation_request_id" = 12 and... 	0.30ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 21 and... 	0.59ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 31 and... 	0.54ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 39 and... 	0.53ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 45 and... 	0.64ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 56 and... 	0.48ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 57 and... 	0.47ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 59 and... 	0.55ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 6 and "vacations"."vacation_request_id"... 	0.66ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 60 and... 	0.53ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 64 and... 	0.31ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 66 and... 	0.39ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 7 and "vacations"."vacation_request_id"... 	0.82ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 75 and... 	0.54ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 79 and... 	0.62ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 83 and... 	0.38ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 90 and... 	0.31ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 91 and... 	0.38ms 	
select * from "vacations" where "vacations"."vacation_request_id" = 96 and... 	0.58ms 	

select * from "year_periods" where "year" = 2024 limit 1 	0.26ms 	
select * from "year_periods" where "year" = 2024 limit 1 	0.35ms 	
select * from "year_periods" where "year" = 2024 limit 1 	0.43ms 	
select * from "year_periods" where "year" = 2024 limit 1 	0.85ms 	
@EwelinaSkrzypacz EwelinaSkrzypacz added investigation things to research php Pull requests that update Php code labels Feb 21, 2024
@mtracz
Copy link
Member

mtracz commented Feb 27, 2024

It might be related to:

kamilpiech97 added a commit that referenced this issue Mar 20, 2024
kamilpiech97 added a commit that referenced this issue Mar 20, 2024
kamilpiech97 added a commit that referenced this issue Mar 20, 2024
# Conflicts:
#	composer.lock
kamilpiech97 added a commit that referenced this issue Mar 20, 2024
kamilpiech97 added a commit that referenced this issue Mar 20, 2024
# Conflicts:
#	app/Domain/DailySummaryRetriever.php
#	app/Domain/DashboardAggregator.php
#	app/Infrastructure/Http/Controllers/VacationRequestController.php
#	composer.lock
kamilpiech97 added a commit that referenced this issue Mar 20, 2024
kamilpiech97 added a commit that referenced this issue Mar 21, 2024
kamilpiech97 added a commit that referenced this issue Mar 25, 2024
* #400 - fixed n+1 quries in app

* - fix

* #398 - wip

* #398 - tidy up queries

* #398 - wip

* - merged main

* #398 - fix

* - laod fix

* #398 - update

* - cr fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation things to research php Pull requests that update Php code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants