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

Fix debug toolbar db connection count #5172

Merged
merged 6 commits into from
Oct 5, 2021
Merged

Fix debug toolbar db connection count #5172

merged 6 commits into from
Oct 5, 2021

Conversation

danielTiringer
Copy link
Contributor

Fixes #5160

Description
The debug toolbar's database tab showed X queries 0 connections - the count of used connections was not reported.
The change counts the unique (name) connections while iterating through the queries, and saves them in a new static variable. Then this variable is used to display the count.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Copy link
Member

@lonnieezell lonnieezell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it's already trying to count the connections that it finds in the constructor. Have you verified what is going wrong there?

@danielTiringer
Copy link
Contributor Author

It looks like it's already trying to count the connections that it finds in the constructor. Have you verified what is going wrong there?

It seems to me that the toolbar's Database collector is created before a database connection is made. Its constructor gets the connections from the config, but at that time, nothing's connected and an empty array is returned.
If we do the getConnections() call at the start of the getTitleDetails() function, the connection is returned as expected.

That can be an alternative too, refreshing the connection array.

@lonnieezell
Copy link
Member

Ah - good point. I think doing a getConnections() at the start of getTitleDetails() as you've mentioned works well. That doesn't have us keeping duplicate info around.

@danielTiringer
Copy link
Contributor Author

Ah - good point. I think doing a getConnections() at the start of getTitleDetails() as you've mentioned works well. That doesn't have us keeping duplicate info around.

Alright, changed the PR accordingly.

@lonnieezell
Copy link
Member

Looks good. Thanks!

@lonnieezell lonnieezell merged commit 3003fd0 into codeigniter4:develop Oct 5, 2021
@danielTiringer danielTiringer deleted the fix-debug-toolbar-db-connection-count branch October 5, 2021 14:01
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

Successfully merging this pull request may close these issues.

Dev: Debug Toolbar should show correct count of connections
3 participants