| | 1533 | |
| | 1534 | /** |
| | 1535 | * Verify that updating a post without taxonomy parameters avoids unnecessary queries. |
| | 1536 | * |
| | 1537 | * @ticket 59354 |
| | 1538 | * @covers ::wp_insert_post |
| | 1539 | */ |
| | 1540 | public function test_update_post_without_taxonomy_params_skips_term_queries() { |
| | 1541 | $post_id = self::factory()->post->create( |
| | 1542 | array( |
| | 1543 | 'post_title' => 'Test Post', |
| | 1544 | 'tags_input' => array( 'tag1' ), |
| | 1545 | 'post_category' => array( 1 ), |
| | 1546 | ) |
| | 1547 | ); |
| | 1548 | |
| | 1549 | // Update with taxonomy params — baseline query count. |
| | 1550 | $queries_before = get_num_queries(); |
| | 1551 | wp_insert_post( |
| | 1552 | array( |
| | 1553 | 'ID' => $post_id, |
| | 1554 | 'post_title' => 'Updated With Taxes', |
| | 1555 | 'tags_input' => array( 'tag1' ), |
| | 1556 | 'post_category' => array( 1 ), |
| | 1557 | ) |
| | 1558 | ); |
| | 1559 | $queries_with_tax = get_num_queries() - $queries_before; |
| | 1560 | |
| | 1561 | // Update without taxonomy params — should use fewer queries. |
| | 1562 | $queries_before = get_num_queries(); |
| | 1563 | wp_insert_post( |
| | 1564 | array( |
| | 1565 | 'ID' => $post_id, |
| | 1566 | 'post_title' => 'Updated Without Taxes', |
| | 1567 | ) |
| | 1568 | ); |
| | 1569 | $queries_without_tax = get_num_queries() - $queries_before; |
| | 1570 | |
| | 1571 | $this->assertLessThan( |
| | 1572 | $queries_with_tax, |
| | 1573 | $queries_without_tax, |
| | 1574 | 'Updating a post without taxonomy parameters should use fewer queries.' |
| | 1575 | ); |
| | 1576 | } |