Skip to content

Commit

Permalink
Add trait for performance hints filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Feb 13, 2025
1 parent af40278 commit 06c15c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
23 changes: 23 additions & 0 deletions inc/Engine/Common/PerformanceHints/Cron/FilterTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Common\PerformanceHints\Cron;

trait FilterTrait {
/**
* Performance Hints Deletion interval filter.
*
* @param string $filter The filter name.
*
* @return int
*/
public function deletion_interval( string $filter ): int {
/**
* Filters the interval (in months) to determine when a performance data entry is considered 'old'.
* Old performance entries are eligible for deletion. By default, a performance entry is considered old if it hasn't been accessed in the last month.
*
* @param int $delete_interval The interval in months after which a performance data entry is considered old. Default is 1 month.
*/
return wpm_apply_filters_typed( 'integer', $filter, 1 );
}
}
10 changes: 3 additions & 7 deletions inc/Engine/Media/AboveTheFold/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WP_Rocket\Engine\Media\AboveTheFold;

use WP_Rocket\Engine\Common\PerformanceHints\Cron\FilterTrait;
use WP_Rocket\Engine\Common\PerformanceHints\FactoryInterface;
use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface as AjaxControllerInterface;
use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface as FrontendControllerInterface;
Expand All @@ -12,6 +13,7 @@
use WP_Rocket\Engine\Common\Context\ContextInterface;

class Factory implements FactoryInterface {
use FilterTrait;

/**
* Ajax Controller instance.
Expand Down Expand Up @@ -98,13 +100,7 @@ public function table(): TableInterface {
* @return QueriesInterface
*/
public function queries(): QueriesInterface {
/**
* Filters the interval (in months) to determine when an Above The Fold (ATF) entry is considered 'old'.
* Old ATF entries are eligible for deletion. By default, an ATF entry is considered old if it hasn't been accessed in the last month.
*
* @param int $delete_interval The interval in months after which an ATF entry is considered old. Default is 1 month.
*/
$delete_interval = wpm_apply_filters_typed( 'integer', 'rocket_atf_cleanup_interval', 1 );
$delete_interval = $this->deletion_interval( 'rocket_atf_cleanup_interval' );

if ( $delete_interval <= 0 ) {
return $this->queries;
Expand Down
11 changes: 3 additions & 8 deletions inc/Engine/Optimization/LazyRenderContent/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WP_Rocket\Engine\Optimization\LazyRenderContent;

use WP_Rocket\Engine\Common\PerformanceHints\Cron\FilterTrait;
use WP_Rocket\Engine\Common\PerformanceHints\FactoryInterface;
use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface as AjaxControllerInterface;
use WP_Rocket\Engine\Common\PerformanceHints\Frontend\ControllerInterface as FrontendControllerInterface;
Expand All @@ -12,6 +13,7 @@
use WP_Rocket\Engine\Common\Context\ContextInterface;

class Factory implements FactoryInterface {
use FilterTrait;

/**
* Ajax Controller instance.
Expand Down Expand Up @@ -98,14 +100,7 @@ public function table(): TableInterface {
* @return QueriesInterface
*/
public function queries(): QueriesInterface {

/**
* Filters the interval (in months) to determine when Below The Fold entry is considered 'old'.
* Old LRC entries are eligible for deletion. By default, LRC entry is considered old if it hasn't been accessed in the last month.
*
* @param int $delete_interval The interval in months after which LRC entry is considered old. Default is 1 month.
*/
$delete_interval = wpm_apply_filters_typed( 'integer', 'rocket_lrc_cleanup_interval', 1 );
$delete_interval = $this->deletion_interval( 'rocket_lrc_cleanup_interval' );

if ( $delete_interval <= 0 ) {
return $this->queries;
Expand Down

0 comments on commit 06c15c5

Please sign in to comment.