Automattic / Automattic/VIP-Coding-Standards
Add check for queries made without post_status or post_type
- Lingua principale
- PHP
- Stelle
- 261
- Fork
- 44
- Merge medio
- 19m
- PR unite (30g)
- 1
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia leggendo l’issue collegata di WordPress-Coding-Standards e le linee guida per la revisione del codice di VIP, quindi esamina gli sniff PHP_CodeSniffer già presenti nel repository. Traccia il modo in cui vengono analizzate le chiamate a get_posts() e WP_Query. Il lavoro è completato quando il nuovo controllo segnala le query che omettono post_status o post_type, con un comportamento coerente con la motivazione indicata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100