mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Posts, Post Types: Add caching to _find_post_by_old_slug and _find_post_by_old_date functions.
Cache result of database queries in `_find_post_by_old_slug` and `_find_post_by_old_date` functions. This means that repeated requests to a url where the page is not found, will result in hitting a cache for sites running persistent object caching. Props Spacedmonkey, dd32, mukesh27, pbearne, flixos90. Fixes #36723. git-svn-id: https://develop.svn.wordpress.org/trunk@53549 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
/**
|
||||
* @group rewrite
|
||||
* @covers wp_old_slug_redirect
|
||||
*/
|
||||
class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase {
|
||||
protected $old_date_redirect_url;
|
||||
@@ -86,6 +87,73 @@ class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase {
|
||||
$this->assertSame( $permalink, $this->old_date_redirect_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36723
|
||||
*/
|
||||
public function test_old_date_slug_redirect_cache() {
|
||||
$old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );
|
||||
|
||||
$time = '2004-01-03 00:00:00';
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => self::$post_id,
|
||||
'post_date' => $time,
|
||||
'post_date_gmt' => get_gmt_from_date( $time ),
|
||||
'post_name' => 'bar-baz',
|
||||
)
|
||||
);
|
||||
|
||||
$permalink = user_trailingslashit( get_permalink( self::$post_id ) );
|
||||
|
||||
$this->go_to( $old_permalink );
|
||||
wp_old_slug_redirect();
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( $permalink, $this->old_date_redirect_url );
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_date_redirect_url );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36723
|
||||
*/
|
||||
public function test_old_date_redirect_cache_invalidation() {
|
||||
global $wpdb;
|
||||
$old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );
|
||||
|
||||
$time = '2004-01-03 00:00:00';
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => self::$post_id,
|
||||
'post_date' => $time,
|
||||
'post_date_gmt' => get_gmt_from_date( $time ),
|
||||
'post_name' => 'bar-baz',
|
||||
)
|
||||
);
|
||||
|
||||
$permalink = user_trailingslashit( get_permalink( self::$post_id ) );
|
||||
|
||||
$this->go_to( $old_permalink );
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_date_redirect_url );
|
||||
|
||||
$time = '2014-02-01 00:00:00';
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $this->post_id,
|
||||
'post_date' => $time,
|
||||
'post_date_gmt' => get_gmt_from_date( $time ),
|
||||
'post_name' => 'bar-baz',
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = get_num_queries();
|
||||
$this->go_to( $permalink );
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_date_redirect_url );
|
||||
$this->assertGreaterThan( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_old_date_redirect_attachment() {
|
||||
$old_permalink = get_attachment_link( self::$attachment_id );
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/**
|
||||
* @group rewrite
|
||||
* @ticket 33920
|
||||
* @covers wp_old_slug_redirect
|
||||
*/
|
||||
class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase {
|
||||
protected $old_slug_redirect_url;
|
||||
@@ -52,6 +53,63 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase {
|
||||
$this->assertSame( $permalink, $this->old_slug_redirect_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36723
|
||||
*/
|
||||
public function test_old_slug_redirect_cache() {
|
||||
$old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
|
||||
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $this->post_id,
|
||||
'post_name' => 'bar-baz',
|
||||
)
|
||||
);
|
||||
|
||||
$permalink = user_trailingslashit( get_permalink( $this->post_id ) );
|
||||
|
||||
$this->go_to( $old_permalink );
|
||||
|
||||
wp_old_slug_redirect();
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( $permalink, $this->old_slug_redirect_url );
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_slug_redirect_url );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36723
|
||||
*/
|
||||
public function test_old_slug_redirect_cache_invalidation() {
|
||||
$old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
|
||||
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $this->post_id,
|
||||
'post_name' => 'bar-baz',
|
||||
)
|
||||
);
|
||||
|
||||
$permalink = user_trailingslashit( get_permalink( $this->post_id ) );
|
||||
|
||||
$this->go_to( $old_permalink );
|
||||
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_slug_redirect_url );
|
||||
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $this->post_id,
|
||||
'post_name' => 'foo-bar',
|
||||
)
|
||||
);
|
||||
$num_queries = get_num_queries();
|
||||
wp_old_slug_redirect();
|
||||
$this->assertSame( $permalink, $this->old_slug_redirect_url );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_old_slug_redirect_attachment() {
|
||||
$file = DIR_TESTDATA . '/images/canola.jpg';
|
||||
$attachment_id = self::factory()->attachment->create_object(
|
||||
|
||||
Reference in New Issue
Block a user