Automattic / Automattic/VIP-Coding-Standards

Add check for queries made without post_status or post_type

Offen
#186 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Type: Enhancement
Vorherrschende Sprache
PHP
Sterne
261
Forks
44
Ø Merge
19 Min.
Gemergte PRs (30 T.)
1

Beschreibung

See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/459.

----

A sniff can be added to flag `get_posts()` and `WP_Query` instances that are made without supplying post_status or post_type. See rationale:

> ## Not defining post_status Or post_type
>
> By default the post_status of a query is set to publish for anonymous users on the front end. It is not set in any WP_ADMIN context including Ajax queries. Queries on the front end for logged in users will also contain an OR statement for private posts created by the logged in user, even if that user is not part of the site. This will reduce the effectiveness of MySQL indexes, specifically the type_status_date index.
>
> The same is true for post_type, if you know that only a certain post_type will match the rest of the query (for example for a taxonomy, meta or just general query) adding the post_type as well as the post_status will help MySQL better utilize the indexes as it’s disposal.

https://vip.wordpress.com/documentation/code-review-what-we-look-for/#not-defining-post_status-or-post_type

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, das verlinkte WordPress-Coding-Standards-Issue und die VIP-Richtlinien zur Codeüberprüfung zu lesen, und untersuche anschließend die vorhandenen PHP_CodeSniffer-Sniffs des Repositorys. Verfolge, wie Aufrufe von get_posts() und WP_Query analysiert werden. Die Aufgabe ist abgeschlossen, wenn die neue Prüfung Abfragen meldet, bei denen post_status oder post_type fehlt, und sich das Verhalten an der angegebenen Begründung orientiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.