Skip to content
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

Media Summary: improve performance with single page load caching #5938

Merged
merged 3 commits into from
Feb 7, 2017
Merged
Changes from 2 commits
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
10 changes: 10 additions & 0 deletions _inc/lib/class.media-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
class Jetpack_Media_Summary {

static $cache = array();
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be private.


static function get( $post_id, $blog_id = 0, $args = array() ) {

$defaults = array(
'max_words' => 16,
'max_chars' => 256,
Expand All @@ -21,6 +24,11 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
$blog_id = get_current_blog_id();
}

$cache_key = md5( "{$blog_id}_{$post_id}_{$args['max_words']}_{$args['max_chars']}" );
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of using md5() here? Probably the md5 sum will be even longer than the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that was a leftover from a wp_cache iteration. Fixed

if ( isset( self::$cache[ $cache_key ] ) ) {
return self::$cache[ $cache_key ];
}

if ( ! class_exists( 'Jetpack_Media_Meta_Extractor' ) ) {
jetpack_require_lib( 'class.media-extractor' );
}
Expand Down Expand Up @@ -242,6 +250,8 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
*/
$return = apply_filters( 'jetpack_media_summary_output', $return, $post_id );

self::$cache[ $cache_key ] = $return;

return $return;
}

Expand Down