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

537 refactor microcaching the api endpoints into using cache decorators #21879

Merged
Show file tree
Hide file tree
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
Feedback Leonidas.
  • Loading branch information
thijsoo committed Dec 10, 2024
commit 4408c2acd4e738ef9dced3a9049ec859a896dda9
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
class Cached_Readability_Score_Results_Collector implements Score_Results_Collector_Interface {

public const READABILITY_SCORES_TRANSIENT = 'wpseo_readability_scores';

/**
* The actual collector implementation.
*
Expand Down Expand Up @@ -50,7 +52,7 @@ public function get_score_results(
?bool $is_troubleshooting
) {
$content_type_name = $content_type->get_name();
$transient_name = Readability_Score_Results_Collector::READABILITY_SCORES_TRANSIENT . '_' . $content_type_name . ( ( $term_id === null ) ? '' : '_' . $term_id );
$transient_name = self::READABILITY_SCORES_TRANSIENT . '_' . $content_type_name . ( ( $term_id === null ) ? '' : '_' . $term_id );

$results = [];
$transient = \get_transient( $transient_name );
Expand All @@ -61,7 +63,9 @@ public function get_score_results(

return $results;
}
$results = $this->readability_score_results_collector->get_score_results( $score_groups, $content_type, $term_id, $is_troubleshooting );

$results = $this->readability_score_results_collector->get_score_results( $score_groups, $content_type, $term_id, $is_troubleshooting );
$results['cache_used'] = false;
if ( $is_troubleshooting !== true ) {
\set_transient( $transient_name, WPSEO_Utils::format_json_encode( $results['scores'] ), \MINUTE_IN_SECONDS );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
class Readability_Score_Results_Collector implements Score_Results_Collector_Interface {

public const READABILITY_SCORES_TRANSIENT = 'wpseo_readability_scores';

/**
* Retrieves readability score results for a content type.
*
Expand Down Expand Up @@ -95,7 +93,6 @@ public function get_score_results( array $readability_score_groups, Content_Type
$end_time = \microtime( true );

$results['scores'] = $current_scores;
$results['cache_used'] = false;
$results['query_time'] = ( $end_time - $start_time );
return $results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
class Cached_SEO_Score_Results_Collector implements Score_Results_Collector_Interface {

public const SEO_SCORES_TRANSIENT = 'wpseo_seo_scores';

/**
* The actual collector implementation.
*
Expand Down Expand Up @@ -49,7 +51,7 @@ public function get_score_results(
?bool $is_troubleshooting
) {
$content_type_name = $content_type->get_name();
$transient_name = SEO_Score_Results_Collector::SEO_SCORES_TRANSIENT . '_' . $content_type_name . ( ( $term_id === null ) ? '' : '_' . $term_id );
$transient_name = self::SEO_SCORES_TRANSIENT . '_' . $content_type_name . ( ( $term_id === null ) ? '' : '_' . $term_id );
$results = [];
$transient = \get_transient( $transient_name );
if ( $is_troubleshooting !== true && $transient !== false ) {
Expand All @@ -59,7 +61,9 @@ public function get_score_results(

return $results;
}
$results = $this->seo_score_results_collector->get_score_results( $score_groups, $content_type, $term_id, $is_troubleshooting );

$results = $this->seo_score_results_collector->get_score_results( $score_groups, $content_type, $term_id, $is_troubleshooting );
$results['cache_used'] = false;
if ( $is_troubleshooting !== true ) {
\set_transient( $transient_name, WPSEO_Utils::format_json_encode( $results['scores'] ), \MINUTE_IN_SECONDS );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
class SEO_Score_Results_Collector implements Score_Results_Collector_Interface {

public const SEO_SCORES_TRANSIENT = 'wpseo_seo_scores';

/**
* Retrieves the SEO score results for a content type.
*
Expand Down Expand Up @@ -97,7 +95,6 @@ public function get_score_results( array $seo_score_groups, Content_Type $conten
$end_time = \microtime( true );

$results['scores'] = $current_scores;
$results['cache_used'] = false;
$results['query_time'] = ( $end_time - $start_time );
return $results;
}
Expand Down
Loading