mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use low-level cache for get_user_data_from_wp_global_styles(). #3517
Closed
peterwilsoncc
wants to merge
5
commits into
WordPress:trunk
from
peterwilsoncc:gb44946-use-low-level-cache-for-user-data-global-styles
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fafe0b8
Add message to each assertion.
peterwilsoncc b75ab81
Use low-level cache for get_user_data_from_wp_global_styles().
peterwilsoncc a60b5b9
Global styles require an admin account to create taxo.
peterwilsoncc c1faaa7
Test for cached queries with logged out users.
peterwilsoncc cc5b0ea
Merge branch 'trunk' into gb44946-use-low-level-cache-for-user-data-g…
peterwilsoncc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,13 @@ | |
*/ | ||
class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { | ||
|
||
/** | ||
* Administrator ID. | ||
* | ||
* @var int | ||
*/ | ||
protected static $administrator_id; | ||
|
||
/** | ||
* Theme root directory. | ||
* | ||
|
@@ -64,6 +71,13 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { | |
public static function set_up_before_class() { | ||
parent::set_up_before_class(); | ||
|
||
self::$administrator_id = self::factory()->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'user_email' => '[email protected]', | ||
) | ||
); | ||
|
||
static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver::class, 'blocks_cache' ); | ||
static::$property_blocks_cache->setAccessible( true ); | ||
static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue(); | ||
|
@@ -620,6 +634,7 @@ function test_merges_child_theme_json_into_parent_theme_json() { | |
* @covers WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles | ||
*/ | ||
function test_get_user_data_from_wp_global_styles_does_not_use_uncached_queries() { | ||
wp_set_current_user( self::$administrator_id ); | ||
$theme = wp_get_theme(); | ||
WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
add_filter( 'query', array( $this, 'filter_db_query' ) ); | ||
|
@@ -629,23 +644,41 @@ function test_get_user_data_from_wp_global_styles_does_not_use_uncached_queries( | |
WP_Theme_JSON_Resolver::clean_cached_data(); | ||
} | ||
$query_count = count( $this->queries ) - $query_count; | ||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' ); | ||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type prior to creation.' ); | ||
|
||
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
$this->assertEmpty( $user_cpt ); | ||
$this->assertEmpty( $user_cpt, 'User CPT is expected to be empty.' ); | ||
|
||
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme, true ); | ||
$this->assertNotEmpty( $user_cpt ); | ||
$this->assertNotEmpty( $user_cpt, 'User CPT is expected not to be empty.' ); | ||
|
||
$query_count = count( $this->queries ); | ||
for ( $i = 0; $i < 3; $i ++ ) { | ||
$new_user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
WP_Theme_JSON_Resolver::clean_cached_data(); | ||
$this->assertSameSets( $user_cpt, $new_user_cpt ); | ||
$this->assertSameSets( $user_cpt, $new_user_cpt, "User CPTs do not match on run {$i}." ); | ||
} | ||
$query_count = count( $this->queries ) - $query_count; | ||
$this->assertSame( 1, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type after creation.' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has increased from zero to one. As the transient has been removed, it's no longer set on post creation so a single query is made on the following call (in run 0), in subsequent runs, it is cached. |
||
} | ||
|
||
/** | ||
* @covers WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles | ||
*/ | ||
function test_get_user_data_from_wp_global_styles_does_not_use_uncached_queries_for_logged_out_users() { | ||
$theme = wp_get_theme(); | ||
WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
add_filter( 'query', array( $this, 'filter_db_query' ) ); | ||
$query_count = count( $this->queries ); | ||
for ( $i = 0; $i < 3; $i++ ) { | ||
WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
WP_Theme_JSON_Resolver::clean_cached_data(); | ||
} | ||
$query_count = count( $this->queries ) - $query_count; | ||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' ); | ||
remove_filter( 'query', array( $this, 'filter_db_query' ) ); | ||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type prior to creation.' ); | ||
|
||
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); | ||
$this->assertEmpty( $user_cpt, 'User CPT is expected to be empty.' ); | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to low level caching in wp-query per discussion on ticket.