Fix invalid Server-Timing logic for database query timing whe $wpdb->queries is null due to no query having been done yet#2346
Conversation
|
@copilot I didn't finish. I was going to say that it is invalid because before the first query is run, the |
Co-authored-by: westonruter <[email protected]>
Fixed in d037da9. The logic now handles the null case correctly:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| // If no queries have been run yet, $wpdb->queries will be null, which is valid (0 queries). | ||
| if ( ! isset( $GLOBALS['wpdb']->queries ) ) { | ||
| $metric->set_value( 0.0 ); | ||
| return; |
There was a problem hiding this comment.
@copilot problem: this is isn't setting the $GLOBALS['perflab_query_time_before_template'] global
There was a problem hiding this comment.
Fixed in 112bdf3. The global $GLOBALS['perflab_query_time_before_template'] is now set to 0.0 when $wpdb->queries is null, ensuring the template-db-queries metric can calculate correctly later.
Co-authored-by: westonruter <[email protected]>
| // If no queries have been run yet, $wpdb->queries will be null, which is valid (0 queries). | ||
| // In this case, template query time is just negative of before-template time. | ||
| if ( ! isset( $GLOBALS['wpdb']->queries ) ) { | ||
| $metric->set_value( ( 0.0 - $GLOBALS['perflab_query_time_before_template'] ) * 1000.0 ); |
There was a problem hiding this comment.
@copilot but a negative query time doesn't really make sense, does it?
There was a problem hiding this comment.
You're right. Fixed in 04afa03. When $wpdb->queries is null, it means no queries have been executed, so the template query time should be 0.0 (not a negative value).
Co-authored-by: westonruter <[email protected]>
|
Disclosure: this bug was brought to my attention by @afragen but I'm on my phone right now, so I tried using Copilot to make the necessary changes. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #2346 +/- ##
==========================================
- Coverage 69.21% 69.20% -0.02%
==========================================
Files 90 90
Lines 7703 7705 +2
==========================================
Hits 5332 5332
- Misses 2371 2373 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Copilot. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Build for testing: performance-lab.zip |
$wpdb->queries is null due to no query having been done yet
This has worked for me. There are no further associated error log messages. |
$wpdb->queriescan be null when no queries have run yet, which is a valid statebefore-template-db-queriesmetric to handle null case by setting metric to 0.0template-db-queriesmetric to handle null case by setting metric to 0.0$GLOBALS['perflab_query_time_before_template']is set even when queries is nullOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.