Skip to content

Commit 585ebfc

Browse files
committed
Improve documentation for WordPress.DB.SlowDBQuery
- Rewrite standard text to mention all four flagged keys, clarify that both array assignments and query-parameter strings are detected. - Replace code examples with examples that stay within 48-character limit and use `<em>` tags. - Remove second code comparison that incorrectly showed `tax_query` and `meta_key` as valid when the sniff warns on all four keys.
1 parent 8c550a2 commit 585ebfc

1 file changed

Lines changed: 11 additions & 61 deletions

File tree

WordPress/Docs/DB/SlowDBQueryStandard.xml

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,28 @@
55
>
66
<standard>
77
<![CDATA[
8-
For performance reason, it's recommended to avoid doing lots of meta queries.
9-
The underlying SQL request generated by those queries can be extremely slow queries especially for complexe meta query.
8+
Usage of the meta_query, meta_key, meta_value, and tax_query keys in array assignments and query-parameter strings is discouraged and should be carefully evaluated. When passed to WordPress database query APIs, these keys can lead to slow queries, especially on large datasets.
109
]]>
1110
</standard>
1211
<code_comparison>
13-
<code title="Valid: Using tax_query to retrieve a list of posts">
12+
<code title="Valid: No potentially slow query keys.">
1413
<![CDATA[
15-
$query = new WP_Query(
16-
array(
17-
'tax_query' => array(
18-
array(
19-
'taxonomy' => 'color',
20-
'field' => 'slug',
21-
'terms' => array(
22-
'blue',
23-
'red',
24-
)
25-
)
26-
)
27-
)
14+
$args = array(
15+
'post_type' => 'post',
2816
);
29-
]]>
30-
</code>
31-
<code title="Invalid: Using meta_query to retrieve a list of posts">
32-
<![CDATA[
33-
$query = new WP_Query(
34-
array(
35-
'meta_query' => array(
36-
array(
37-
'key' => 'color',
38-
'compare' => 'IN',
39-
'value' => array(
40-
'blue',
41-
'red',
42-
)
43-
)
44-
)
45-
)
46-
);
47-
]]>
48-
</code>
49-
</code_comparison>
50-
<code_comparison>
51-
<code title="Valid: in case of binary metadata (true/false) check if meta_key exist and remove it otherwise">
52-
<![CDATA[
53-
// mark post 123 as "featured"
54-
update_post_meta( 123, 'is_featured', true );
5517
56-
// remove "featured" state for post 456
57-
delete_post_meta( 456, 'is_featured' );
5818
59-
$query = new WP_Query(
60-
array(
61-
'meta_key' => 'is_featured'
62-
),
63-
);
19+
$query = 'post_type=post&orderby=date';
6420
]]>
6521
</code>
66-
<code title="Invalid: check for the value of a binary metadata, which is slower">
22+
<code title="Invalid: Using potentially slow query keys.">
6723
<![CDATA[
68-
// mark post 123 as "featured"
69-
update_post_meta( 123, 'is_featured', true );
70-
71-
// mark post 456 as not "featured"
72-
update_post_meta( 456, 'is_featured', false );
73-
74-
$query = new WP_Query(
75-
array(
76-
'meta_key' => 'is_featured',
77-
'meta_value' => true
78-
),
24+
$args = array(
25+
'<em>meta_key</em>' => 'color',
26+
'<em>meta_value</em>' => 'blue',
7927
);
28+
29+
$query = 'post_type=post&<em>meta_key</em>=featured';
8030
]]>
8131
</code>
8232
</code_comparison>

0 commit comments

Comments
 (0)