Reputation: 2895
I have a portal made with Symfony 3.4 and Sonata Admin.
In a specific admin page there are a lot of generated queries. I used the profiler to track them down but I cannot see where they generated from:
There is the same query repeated a lot of times with different IDs:
Is there a way to understand where they are generated? I saw that post and it seems impossible to do at the moment:
https://github.com/doctrine/DoctrineBundle/issues/722
Can't I just drop a dump/die
somewhere in the profiler to get the specific line?
Upvotes: 4
Views: 4369
Reputation: 131
Since v1.11.0, Doctrine Bundle can display query backtrace in Symfony Profiler. This is may be helpful to find what code caused the specific query to be executed.
The feature is disabled by default but you can enable it using profiling_collect_backtrace
configuration in your doctrine connection settings.
See https://symfony.com/blog/new-in-doctrinebundle-1-11-0#store-backtraces-when-profiling-queries for more information.
Upvotes: 10
Reputation: 2895
I just found this plugin which is doing exactly what I need:
https://github.com/VincentChalnot/DoctrineDebugBundle
It seems to work fine and it's showing the stack trace from the query.
Upvotes: 4
Reputation: 1041
It looks like there is no easy way to track query initiators but I found the following post explaining why you may see multiple similar queries: Doctrine2 in Symfony2: How can I see which object-call leads into a query?
Upvotes: 0
Reputation: 15010
Is not an easy enought task, but I think that you can obtain some hints with the debug log info, the doctrine queries and the execution timeline.
In the timeline you can see when the doctrine execute a query, and with the info from Doctrine and debug you can join the execution time and the executed query.
I hope this info can help you
Upvotes: 1