Automattic / Automattic/VIP-Coding-Standards
Add check for queries made without post_status or post_type
- Ngôn ngữ chính
- PHP
- Star
- 261
- Fork
- 44
- Merge trung bình
- 19 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách đọc issue WordPress-Coding-Standards được liên kết và hướng dẫn review code của VIP, sau đó kiểm tra các sniff PHP_CodeSniffer hiện có trong repository. Theo dõi cách các lời gọi đến get_posts() và WP_Query được phân tích. Hoàn thành khi kiểm tra mới phát hiện các query bỏ qua post_status hoặc post_type, với hành vi nhất quán với lý do đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100