Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve caching.
  • Loading branch information
spacedmonkey committed Jun 17, 2022
commit 82ffd45ccb8b65dde0796e00ff66c11bee93a5e2
11 changes: 5 additions & 6 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
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];
Expand All @@ -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 );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @xknown for context here.


return $user_cpt;
}
Expand Down