Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

foxdevuz's avatar

Optimization Laravel Code

Hello everyone.

I have a telegram bot which is designed for solve quizes and there's one function that checks timeout or not... but since bot users are about 90k the logic that I wrote it being useless... what I did is:

  1. gets all users who's currently solving tests
  2. checks if time is out or not now the problamatic part
  3. does foreach for every user who's solving test right now and sends new test but in this time it also must update the [test time, current_index]. and also, if there's no more tests it should end the test which means there's if statement also. I tried to but them to jobs but didn't work.

One of the problems here the whole timeUp check query is taking approximately 30000ms - 50000ms (30-50s) but it should check if there's tests which time is up.

I really do not know what to do and how to do... I make indexing for these tables it helped but still not that fast...

Could anyone help me with this ? Thanks

0 likes
4 replies
foxdevuz's avatar

The "Telescope" is showing

Query
1245 queries, 1234 of which are duplicated

but I did not see duplicated queries in code...

I am stuck at this point

foxdevuz's avatar

@tisuchi no I did not and I think it also shows the request, queries, cache and so on. just like telescope so I have doubt it will help or not....

but thanks anyway

RemiM's avatar

@foxdevuz Laravel debugbar is a great tool to use, it can help in many ways.

Anyway, like @tisuchi mentioned, it's most likely a N+1 issue.

You should check the official documentation about Eager Loading.

1 like

Please or to participate in this conversation.