Skip to content

Commit

Permalink
fix: remove wildcard from cache invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Jun 16, 2022
1 parent dc4cd04 commit 49a20dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function clearPost($postId)

$permalink = rtrim($permalink, '/').'/';
$postType = get_post_type_object($postId);
$urlsToClear = new Collection([$permalink, $permalink.'*', rtrim(home_url(), '/').'/']);
$urlsToClear = new Collection([$permalink, rtrim(home_url(), '/').'/']);

// Custom post archive
if ('page' === get_site_option('show_on_front') && !empty(get_site_option('page_for_posts'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ public function testClearPostAddsCategoryUrls()
->willReturn('category_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(5))
$pageCacheClient->expects($this->exactly(4))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('category_url')],
[$this->identicalTo('rest_url/wp/v2/categories/24/')]
Expand Down Expand Up @@ -195,11 +194,10 @@ public function testClearPostAddsCustomPostArchive()
->willReturn('home_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(4))
$pageCacheClient->expects($this->exactly(3))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('post_archive_permalink')]
);
Expand Down Expand Up @@ -276,11 +274,10 @@ public function testClearPostAddsCustomPostTypeArchiveAndFeed()
->willReturn('custom_post_type_archive_feed_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(5))
$pageCacheClient->expects($this->exactly(4))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('custom_post_type_archive_url')],
[$this->identicalTo('custom_post_type_archive_feed_url')]
Expand Down Expand Up @@ -375,11 +372,10 @@ public function testClearPostAddsPostRelatedUrls()
->willReturn('post_commments_feed_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(12))
$pageCacheClient->expects($this->exactly(11))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('author_posts_url')],
[$this->identicalTo('author_feed_url')],
Expand Down Expand Up @@ -477,11 +473,10 @@ public function testClearPostAddsPublicTaxonomyUrls()
->willReturn([$taxonomyTerm]);

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(5))
$pageCacheClient->expects($this->exactly(4))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('taxonomy_url')],
[$this->identicalTo('rest_url/wp/v2/taxonomy/slug/')]
Expand Down Expand Up @@ -552,11 +547,10 @@ public function testClearPostAddsRestApiEndpointIfWeHavePostTypeObject()
->willReturn('home_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(4))
$pageCacheClient->expects($this->exactly(3))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('rest_url/wp/v2/pages/42/')]
);
Expand Down Expand Up @@ -631,11 +625,10 @@ public function testClearPostAddsTagUrls()
->willReturn('tag_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(5))
$pageCacheClient->expects($this->exactly(4))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')],
[$this->identicalTo('tag_url')],
[$this->identicalTo('rest_url/wp/v2/tag/24/')]
Expand Down Expand Up @@ -783,11 +776,10 @@ public function testClearPostFixesTrashedPostPermalinkUrl()
->willReturn('home_url');

$pageCacheClient = $this->getContentDeliveryNetworkPageCacheClientInterfaceMock();
$pageCacheClient->expects($this->exactly(3))
$pageCacheClient->expects($this->exactly(2))
->method('clearUrl')
->withConsecutive(
[$this->identicalTo('permalink/')],
[$this->identicalTo('permalink/*')],
[$this->identicalTo('home_url/')]
);

Expand Down

0 comments on commit 49a20dd

Please sign in to comment.