close
Skip to content

DB/SlowDBQuery: add XML documentation#2699

Merged
dingo-d merged 4 commits intoWordPress:developfrom
rodrigoprimo:docs-slow-db-query
Mar 5, 2026
Merged

DB/SlowDBQuery: add XML documentation#2699
dingo-d merged 4 commits intoWordPress:developfrom
rodrigoprimo:docs-slow-db-query

Conversation

@rodrigoprimo
Copy link
Collaborator

Description

This PR adds XML documentation for the WordPress.DB.SlowDBQuery sniff.

The documentation is based on the work started by @petitphp in #2464. I used the original commit and, in a separate commit, made the following changes to the original version of the documentation:

  • Rewrite standard text to mention all four flagged keys, clarify that both array assignments and query-parameter strings are detected.
  • Replace code examples with examples that stay within 48-character limit and use <em> tags.
  • Remove second code comparison that incorrectly showed tax_query and meta_key as valid when the sniff warns on all four keys.

I suggest squashing the two commits before merging. I'm opening the PR without doing that to make it easier to tell my changes apart from the original changes.

Suggested changelog entry

N/A

Related issues/external references

Related to: #1722
Supersedes: #2464
Closes #2464

petitphp and others added 2 commits February 10, 2026 10:09
- Rewrite standard text to mention all four flagged keys, clarify
  that both array assignments and query-parameter strings are
  detected.
- Replace code examples with examples that stay within 48-character
  limit and use `<em>` tags.
- Remove second code comparison that incorrectly showed
  `tax_query` and `meta_key` as valid when the sniff warns on all
  four keys.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

@rodrigoprimo Thanks for working on this!

The code samples are confusing to me as the description and the sniff name point to this being about database queries, but none of the code samples are querying the database.

While I realize that the sniff doesn't actually check the keys are used in the context of a database query, I think the code samples in the docs should demonstrate what we're concerned about.

To that end, I've left some suggestions inline, but there may be more things which can be improved ?

Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
@rodrigoprimo
Copy link
Collaborator Author

Thanks for the review, @jrfnl! Good point about the examples showing database query context. I applied your suggestions for the WP_Query examples.

I'm unsure whether to make a similar change for the string example. I considered the example below. The code works, but I don't think it's a good idea to use an undocumented pattern in the valid example. The documentation doesn't mention that get_posts() accepts a string.

$posts = get_posts(
    'post_type=post&orderby=date'
);

Do you think the documentation is good as is, or should we think a bit more about the string example?

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

I'm unsure whether to make a similar change for the string example. I don't think it's a good idea to use an undocumented pattern in the valid example. The documentation doesn't mention that get_posts() accepts a string.

To me, this means that a PR to the WP codebase to fix the function documentation may be in order.

Do you think the documentation is good as is, or should we think a bit more about the string example?

I'm okay with the documentation as-is. I do think it would be good to improve the string example, but I don't see that as a blocker for this PR. That can be done in a future iteration when someone comes up with a better code sample.

For now, IMO, this will work fine.

Thanks @rodrigoprimo !

@jrfnl
Copy link
Member

jrfnl commented Mar 5, 2026

For whomever merged this, please squash-merge this PR.

Copy link
Member

@dingo-d dingo-d left a comment

Choose a reason for hiding this comment

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

Left just one comment

Copy link
Member

@dingo-d dingo-d left a comment

Choose a reason for hiding this comment

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

Better now 👍🏼

@dingo-d dingo-d merged commit 1dbd8ad into WordPress:develop Mar 5, 2026
31 checks passed
@rodrigoprimo rodrigoprimo deleted the docs-slow-db-query branch March 5, 2026 13:58
@rodrigoprimo
Copy link
Collaborator Author

To me, this means that a PR to the WP codebase to fix the function documentation may be in order.

Here is the core ticket: https://core.trac.wordpress.org/ticket/64813

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants