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

WPQueryParams: sniff for exclude array key being set #589

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Oct 19, 2020

Note: I've split this change into two commits to allow for moving the second commit to the 3.0.0 release if so desired.


WPQueryParams: sniff for exclude array key being set

This:

  • Switches the WordPressVIPMinimum.Performance.WPQueryParams sniff over to use the WordPressCS AbstractArrayAssignmentRestrictionsSniff as the parent sniff.
  • Adds sniffing for the exclude array key via the AbstractArrayAssignmentRestrictionsSniff sniff logic.

Includes unit test.

Fixes #369

WPQueryParams: defer to the parent sniff

This changes over the existing keys being sniffed for by this sniff to use the logic from the new AbstractArrayAssignmentRestrictionsSniff parent instead of custom logic.

Note: this is a BC-break as the error codes for the existing checks change!

  • WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn is now WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
  • WordPressVIPMinimum.Performance.WPQueryParams.SuppressFiltersTrue is now WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters

@jrfnl jrfnl added this to the 2.3.0 milestone Oct 19, 2020
@jrfnl jrfnl requested a review from a team as a code owner October 19, 2020 08:42
'type' => 'warning',
'message' => 'Using `post__not_in` should be done with caution, see https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.',
'keys' => [
'post__not_in',
Copy link
Contributor

Choose a reason for hiding this comment

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

Since post__not_in and exclude are the same, should we punt it into one group?

Copy link
Collaborator Author

@jrfnl jrfnl Oct 23, 2020

Choose a reason for hiding this comment

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

I considered that, but we'd need to have a careful think about the warning message in that case as using the existing message would be confusing (which is why they are in separate groups now).

Copy link
Contributor

Choose a reason for hiding this comment

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

We can definitely revamp the warning message to something more ambiguous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll have a think about it. Suggestions welcome.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like...
"Using exclusionary parameters should be done with caution, see https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information."

We can even re-vamp the documentation a bit to account for it as well.

@GaryJones
Copy link
Contributor

As noted in #369, I'd prefer the second commit to be punted to 3.0 - thanks for thinking ahead and splitting out the code into the two commits!

This:
* Switches the `WordPressVIPMinimum.Performance.WPQueryParams` sniff over to use the WordPressCS `AbstractArrayAssignmentRestrictionsSniff` as the parent sniff.
* Adds sniffing for the `exclude` array key via the `AbstractArrayAssignmentRestrictionsSniff` sniff logic.

Includes unit test.
@jrfnl
Copy link
Collaborator Author

jrfnl commented Oct 25, 2020

@GaryJones I've removed the second commit from the PR (kept locally with a "wait/3.0" annotation).

@rebeccahum I've changed the group key for exclude to PostNotIn so those two keys can be joined in one group with one message when we address part 2 of this issue.

Once this PR is merged, a new issue should be opened for 3.0 as a reminder that the rest of the sniff still needs to be switched over to the new abstract.

@jrfnl jrfnl force-pushed the fix/369-exclude-arg-in-get_posts branch from 3e009d0 to 20fdf8b Compare October 25, 2020 10:11
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

Flag 'exclude' args in get_posts()
3 participants