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

Closes #5885: Preload: Don't try to preload private pages #5920

Merged
merged 34 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8609ad2
Updated to not cache private pages
jeawhanlee May 12, 2023
549660f
Updated tests
jeawhanlee May 12, 2023
b74ea74
Update test case
jeawhanlee May 12, 2023
c6574d7
Return early when not a post
jeawhanlee May 16, 2023
46e18bf
Enhance code readability
jeawhanlee May 16, 2023
9a0f29d
Remove post changed to private from cache table
jeawhanlee May 18, 2023
7273824
Updated method
jeawhanlee May 18, 2023
09ff7ac
Check for private post
jeawhanlee Jun 1, 2023
1006e72
Updated tests
jeawhanlee Jun 1, 2023
dcd141d
Check for private post
jeawhanlee Jun 1, 2023
27cbaf9
Merge branch 'develop' into enhancement/5885-do-not-preload-private-p…
jeawhanlee Jun 2, 2023
19be1fc
Change method logic
jeawhanlee Jun 7, 2023
1872f1f
Add trailing slash
jeawhanlee Jun 7, 2023
4d232ab
Cast publish status
jeawhanlee Jun 7, 2023
144ba17
Updated tests
jeawhanlee Jun 7, 2023
504369c
Merge branch 'develop' into enhancement/5885-do-not-preload-private-p…
jeawhanlee Jun 13, 2023
6c38e0d
Updated to get private post of any post type
jeawhanlee Jun 16, 2023
647a388
Get all private posts
jeawhanlee Jun 22, 2023
64b1d4a
Removed call to is_private method
jeawhanlee Jun 22, 2023
98a4dfd
Updated tests
jeawhanlee Jun 22, 2023
f4ddde1
Added new filter callback to remove private urls
jeawhanlee Jun 22, 2023
5d6a845
Updated tests
jeawhanlee Jun 22, 2023
aaf38fd
Updated tests
jeawhanlee Jun 22, 2023
c4692a9
Updated test
jeawhanlee Jun 22, 2023
fec069c
Fixed failing test
jeawhanlee Jun 22, 2023
c29bec8
Fixed failing test
jeawhanlee Jun 22, 2023
3863962
Fixed failing integration test
jeawhanlee Jun 23, 2023
15ef5b3
Updated callback method
jeawhanlee Jun 23, 2023
1235cf3
Updated method
jeawhanlee Jun 23, 2023
e511455
Added tests
jeawhanlee Jun 23, 2023
7048d8c
Updated test
jeawhanlee Jun 23, 2023
6762e10
Added minimum mock for WP_Query class
jeawhanlee Jun 23, 2023
02baaf8
Adjust test
jeawhanlee Jun 26, 2023
8826018
Merge branch 'develop' into enhancement/5885-do-not-preload-private-p…
vmanthos Jun 27, 2023
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
13 changes: 13 additions & 0 deletions inc/Engine/Preload/Controller/CheckExcludedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,17 @@ protected function is_excluded_by_filter( string $url ): bool {
}
return false;
}

/**
* Checks that a page is private.
*
* @param string $url Page url.
*
* @return bool Return true if page is private; false otherwise.
*/
protected function is_private( string $url ) : bool {
$post_id = url_to_postid( $url );
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved

return 'private' === get_post_status( $post_id );
}
}
4 changes: 4 additions & 0 deletions inc/Engine/Preload/Controller/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function __construct( Cache $query ) {
public function partial_clean( array $urls ) {
foreach ( $urls as $url ) {

if ( $this->is_private( $url ) ) {
continue;
}

if ( ! $this->is_excluded_by_filter( $url ) ) {
$this->query->create_or_update(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
'is_excluded' => false,
'is_excluded_by_filter' => false,
'is_private' => false,
],
'expected' => [
'urls' => [
Expand All @@ -34,6 +35,7 @@
],
'is_excluded' => true,
'is_excluded_by_filter' => false,
'is_private' => false,
],
'expected' => [
'urls' => [
Expand All @@ -60,6 +62,28 @@
],
'is_excluded' => true,
'is_excluded_by_filter' => true,
'is_private' => false,
],
'expected' => [
'urls' => [
[
'url',
],
[
'url1',
]
]
]
],
'excludePostStatusWithPrivateStatus' => [
'config' => [
'urls' => [
'url',
'url1',
],
'is_excluded' => true,
'is_excluded_by_filter' => true,
'is_private' => true,
],
'expected' => [
'urls' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,39 @@ protected function setUp(): void
{
parent::setUp();
$this->query = $this->createMock(Cache::class);
$this->controller = Mockery::mock(ClearCache::class . '[is_excluded,is_excluded_by_filter]', [$this->query])
$this->controller = Mockery::mock(ClearCache::class . '[is_excluded,is_excluded_by_filter,is_private]', [$this->query])
->shouldAllowMockingProtectedMethods();
}


/**
* @dataProvider configTestData
*/
public function testShouldDoAsExpected($config, $expected) {

foreach ($config['urls'] as $url) {
$this->controller->expects()->is_excluded_by_filter($url)->andReturn($config['is_excluded']);
$this->controller->shouldReceive('is_excluded_by_filter')->with($url)->andReturn($config['is_excluded_by_filter']);
$this->controller->expects()->is_private($url)->andReturn($config['is_private']);
if ( ! $config['is_private'] ) {
$this->controller->expects()->is_excluded_by_filter($url)->andReturn($config['is_excluded']);
$this->controller->shouldReceive('is_excluded_by_filter')->with($url)->andReturn($config['is_excluded_by_filter']);
}
else{
$this->controller->expects()->is_excluded_by_filter($url)->never();
$this->controller->shouldReceive('is_excluded_by_filter')->never();
}
}

if ( $config['is_private'] ) {
$this->query->expects($this->never())->method('create_or_update');
$this->query->expects($this->never())->method('delete_by_url');
}
if(! $config['is_excluded']) {
if(! $config['is_excluded_by_filter']) {
$this->query->expects(self::atLeastOnce())->method('create_or_update')->withConsecutive(...$expected['urls']);
} else {
$this->query->expects(self::atLeastOnce())->method('delete_by_url')->withConsecutive(...$expected['urls']);
else {
if(! $config['is_excluded']) {
if(! $config['is_excluded_by_filter']) {
$this->query->expects(self::atLeastOnce())->method('create_or_update')->withConsecutive(...$expected['urls']);
} else {
$this->query->expects(self::atLeastOnce())->method('delete_by_url')->withConsecutive(...$expected['urls']);
}
}
}

Expand Down