-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Improve caching and logic in get_user_data_from_wp_global_styles. #2414
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
075d00a
Improve caching of global styles.
spacedmonkey 2da31ee
Merge branch 'trunk' into fix/global-query
spacedmonkey 83f9579
Add some unit tests.
spacedmonkey 82ffd45
Improve caching.
spacedmonkey 95667ce
Handle more edge cases.
spacedmonkey 71bcb6c
Improve tests.
spacedmonkey 478fa51
Merge branch 'trunk' into fix/global-query
spacedmonkey 8bb1cd7
Add expiration back again.
spacedmonkey 32d7306
Fix style.
spacedmonkey 7482d90
Merge branch 'trunk' into fix/global-query
spacedmonkey 12e6322
Fix test.
spacedmonkey 67537a2
Apply suggestions from code review
spacedmonkey 0389421
Merge branch 'trunk' into fix/global-query
spacedmonkey 76fd86c
Formatting of tests.
spacedmonkey 8e567de
Fix styling.
spacedmonkey 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
Improve caching.
- Loading branch information
commit 82ffd45ccb8b65dde0796e00ff66c11bee93a5e2
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -275,15 +275,15 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post | |
|
|
||
| $cache_key = sprintf( 'wp_global_styles_%s', md5( serialize( $args ) ) ); | ||
| $post_id = (int) get_transient( $cache_key ); | ||
| if ( $post_id > 0 ) { | ||
| return get_post( $post_id, ARRAY_A ); | ||
| } | ||
|
|
||
| // Special case: '-1' is a results not found. | ||
| if ( -1 === $post_id && ! $create_post ) { | ||
| return $user_cpt; | ||
| } | ||
|
|
||
| if ( $post_id > 0 && in_array( get_post_status( $post_id ), (array) $post_status_filter, true ) ) { | ||
spacedmonkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return get_post( $post_id, ARRAY_A ); | ||
| } | ||
|
|
||
| $recent_posts = new WP_Query( $args ); | ||
| if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) { | ||
| $user_cpt = $recent_posts[0]; | ||
|
|
@@ -303,8 +303,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post | |
| ); | ||
| $user_cpt = get_post( $cpt_post_id, ARRAY_A ); | ||
| } | ||
| $cache_expiration = $user_cpt ? DAY_IN_SECONDS : HOUR_IN_SECONDS; | ||
| set_transient( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, $cache_expiration ); | ||
| set_transient( $cache_key, $user_cpt ? $user_cpt['ID'] : -1 ); | ||
|
||
|
|
||
| return $user_cpt; | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.