Automattic / Automattic/VIP-Coding-Standards
Add check for queries made without post_status or post_type
- 主要言語
- PHP
- スター
- 261
- フォーク
- 44
- 平均マージ
- 19分
- マージ済み PR(30日)
- 1
説明
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
コントリビューションガイド
調査の方向性
まず、リンクされている WordPress-Coding-Standards の issue と VIP のコードレビューガイダンスを読み、次にリポジトリに既存する PHP_CodeSniffer の sniff を調査します。get_posts() と WP_Query の呼び出しがどのように解析されるかを追跡します。新しいチェックが post_status または post_type を省略したクエリを検出し、記載された根拠と一貫した動作をすることが完了の条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100