Giter Site home page Giter Site logo

Comments (8)

rhertogh avatar rhertogh commented on June 10, 2024 1

Yes, a separate tab would indeed be good. Then it can even be grouped by the stack trace.

from yii2-debug.

samdark avatar samdark commented on June 10, 2024

How many actual queries are there?

from yii2-debug.

rhertogh avatar rhertogh commented on June 10, 2024

@samdark

How many actual queries are there?

In total there were 70 queries in the example. The excessive 20 queries were in this case caused because the related models were not eager loaded. So in this case the total number of queries for the request could be reduced to 51 (70 - 20 duplicates + 1 for the eager loading).

from yii2-debug.

bizley avatar bizley commented on June 10, 2024

What is the actual benefit of this?

from yii2-debug.

rhertogh avatar rhertogh commented on June 10, 2024

@bizley
The main goal is to detect programming mistakes like not eager loading data. For example a REST API index action returns 20 models. When serializing those models a lot of additional queries might automatically be executed to populate relational data when there is no eager loading of those relations.
The current 'duplicates' functionality is not able to detect those repeated calls since the query itself is different each time (in the screenshot above the id value in SELECT * FROM users WHERE id=x.).

Similar to the current $criticalQueryThreshold we can add a $repeatingCallerCallsCriticalThreshold (with a much lower value) providing a warning if the same code makes a lot of DB queries.

from yii2-debug.

samdark avatar samdark commented on June 10, 2024

So the actual number of queries per line is not 1 but 20? If so then it could be considered a bug that it displays 1.

from yii2-debug.

rhertogh avatar rhertogh commented on June 10, 2024

No, there is only one query per row, similar to the current 'duplicates'.
If there are two duplicate queries, you would see 2 rows, each showing 2 duplicates.
For reference, the existing 'duplicates' implementation: #281 (comment)

Duplicates occur when the exact same query is executed (could be the same or different source code). E.g:

File:Line Query DB Panel 'Duplicates' DB Panel 'Repeating calls'
User.php:20 SELECT * FROM user WHERE id=123; 2 0
Test.php:55 SELECT * FROM user WHERE id=123; 2 0

Results in 2 duplicates, 0 repeating callers.

Repeating calls occur when the exact same source code makes a DB call (could be the same or different queries). E.g:

File:Line Query DB Panel 'Duplicates' DB Panel 'Repeating calls'
User.php:75 SELECT * FROM user WHERE id=123; 0 3
User.php:75 SELECT * FROM user WHERE id=456; 0 3
User.php:75 SELECT * FROM user WHERE id=789; 0 3

Results in 0 duplicates, 1 repeating caller making 3 repeating calls.

A combination of both duplicates and repeating calls is also possible E.g:

File:Line Query DB Panel 'Duplicates' DB Panel 'Repeating calls'
User.php:75 SELECT * FROM user WHERE id=123; 2 3
User.php:75 SELECT * FROM user WHERE id=456; 0 3
User.php:75 SELECT * FROM user WHERE id=789; 0 3
Test.php:55 SELECT * FROM user WHERE id=123; 2 0

Results in 2 duplicates, 1 repeating caller making 3 repeating calls.

from yii2-debug.

samdark avatar samdark commented on June 10, 2024

Ah, now I get it. While it's useful, I think it likely should be a separate panel since this number is not per query.

from yii2-debug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.