fix: reuse CHRNX term caches
This commit is contained in:
2 files changed
+48
-2
No files matched your search
@@ -172,6 +172,48 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
$this->assertStringNotContainsString( 'placeholder', strtolower( $output ) );
|
||||
}
|
||||
|
||||
/** Primed editorial cards reuse relationship caches instead of querying once per fallback. */
|
||||
public function test_maximum_featured_render_has_no_term_relationship_n_plus_one() {
|
||||
for ( $index = 1; $index <= 12; ++$index ) {
|
||||
$post_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_title' => 'Cached card ' . $index,
|
||||
'post_date' => sprintf( '2026-05-%02d 10:00:00', $index ),
|
||||
)
|
||||
);
|
||||
wp_set_object_terms( $post_id, 'research', 'chrnx_topic' );
|
||||
}
|
||||
|
||||
$ids = chrnx_get_featured_story_ids( 12 );
|
||||
$this->assertCount( 12, $ids );
|
||||
_prime_post_caches( $ids, true, true );
|
||||
|
||||
$term_queries = array();
|
||||
$capture = static function ( $sql ) use ( &$term_queries ) {
|
||||
if ( false !== stripos( $sql, 'term_relationships' ) ) {
|
||||
$term_queries[] = $sql;
|
||||
}
|
||||
return $sql;
|
||||
};
|
||||
add_filter( 'query', $capture );
|
||||
try {
|
||||
$output = render_block(
|
||||
array(
|
||||
'blockName' => 'chrnx/featured-stories',
|
||||
'attrs' => array( 'limit' => 12 ),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
remove_filter( 'query', $capture );
|
||||
}
|
||||
|
||||
$this->assertSame( 12, substr_count( $output, '<article' ) );
|
||||
$this->assertSame( array(), $term_queries, 'Warm rendering must not issue per-card relationship queries.' );
|
||||
}
|
||||
|
||||
/** Stored title markup is displayed literally and cannot inject executable elements. */
|
||||
public function test_editorial_cards_escape_stored_title_markup() {
|
||||
$title = '<b title="> x" onmouseover="alert(1)"><script>alert(2)</script></b>';
|
||||
|
||||
Reference in new issue
Block a user