-
Notifications
You must be signed in to change notification settings - Fork 30
Introduce wp profile queries command
#207
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
Draft
Copilot
wants to merge
12
commits into
main
Choose a base branch
from
copilot/add-wp-profile-queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6dd9c91
Initial plan
Copilot 1aa88d1
Add basic wp profile queries command implementation
Copilot 7e45434
Add hook and callback filtering support for queries command
Copilot 60d5396
Add documentation for wp profile queries command
Copilot 4a5f4cb
Update src/QueryLogger.php
swissspidy 26ec9f7
Update src/Logger.php
swissspidy 071cb94
Update features/profile.feature
swissspidy 9e5aa60
Improve first test scenario to add custom queries
Copilot ec1564a
Lint fix
swissspidy 28e1e4d
Fix PHP warnings for non-numeric values in Formatter
Copilot 1f255b9
Address code review feedback: fix callback filtering and reset query_…
Copilot cc09ca2
Update src/Command.php
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| Feature: Profile database queries | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Show all database queries | ||
| Given a WP install | ||
| And a wp-content/mu-plugins/test-queries.php file: | ||
| """ | ||
| <?php | ||
| add_action( 'init', function() { | ||
| global $wpdb; | ||
| $wpdb->query( "SELECT 1 as test_query_one" ); | ||
| $wpdb->query( "SELECT 2 as test_query_two" ); | ||
| }); | ||
| """ | ||
|
|
||
| When I run `wp profile queries --fields=query,time` | ||
| Then STDOUT should contain: | ||
| """ | ||
| query | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| time | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| SELECT 1 as test_query_one | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| SELECT 2 as test_query_two | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| total | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Show queries with specific fields | ||
| Given a WP install | ||
|
|
||
| When I run `wp profile queries --fields=query,time` | ||
| Then STDOUT should contain: | ||
| """ | ||
| query | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| time | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| SELECT | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Order queries by execution time | ||
| Given a WP install | ||
|
|
||
| When I run `wp profile queries --fields=time --orderby=time --order=DESC` | ||
| Then STDOUT should contain: | ||
| """ | ||
| time | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Display queries in JSON format | ||
| Given a WP install | ||
|
|
||
| When I run `wp profile queries --format=json --fields=query,time` | ||
| Then STDOUT should contain: | ||
| """ | ||
| "query" | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| "time" | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Filter queries by hook | ||
| Given a WP install | ||
| And a wp-content/mu-plugins/query-test.php file: | ||
| """ | ||
| <?php | ||
| add_action( 'init', function() { | ||
| global $wpdb; | ||
| $wpdb->query( "SELECT 1 as test_query" ); | ||
| }); | ||
| """ | ||
|
|
||
| When I run `wp profile queries --hook=init --fields=query,callback` | ||
| Then STDOUT should contain: | ||
| """ | ||
| SELECT 1 as test_query | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| @require-wp-4.0 | ||
| Scenario: Filter queries by callback | ||
| Given a WP install | ||
| And a wp-content/mu-plugins/callback-test.php file: | ||
| """ | ||
| <?php | ||
| function my_test_callback() { | ||
| global $wpdb; | ||
| $wpdb->query( "SELECT 2 as callback_test" ); | ||
| } | ||
| add_action( 'init', 'my_test_callback' ); | ||
| """ | ||
|
|
||
| When I run `wp profile queries --callback=my_test_callback --fields=query,hook` | ||
| Then STDOUT should contain: | ||
| """ | ||
| SELECT 2 as callback_test | ||
| """ | ||
| And STDERR should be empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Potential issue with query map overwriting. When multiple loggers track the same query index (e.g., nested hooks), the check
! isset( $query_map[ $query_index ] )at line 602 prevents overwriting. This means the first logger's hook/callback will be used, but in nested scenarios, this might not be the most specific or accurate mapping. Consider whether the first-logger-wins approach is the intended behavior, or if you need to track multiple hooks/callbacks per query.