Skip to content
Snippets Groups Projects
Verified Commit 08bf243d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3423272 by catch, kristiaanvandeneynde: Return early from more cache tag operations

parent 3923a9f8
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,6 @@ public function rootTransactionEndCallback($success) {
* Implements \Drupal\Core\Cache\CacheTagsInvalidatorInterface::invalidateTags()
*/
public function invalidateTags(array $tags) {
// Only invalidate tags once per request unless they are written again.
foreach ($tags as $key => $tag) {
if (isset($this->invalidatedTags[$tag])) {
unset($tags[$key]);
......@@ -139,6 +138,11 @@ public function isValid($checksum, array $tags) {
*/
protected function calculateChecksum(array $tags) {
$checksum = 0;
// If there are no cache tags, then there is no cache tag to checksum,
// so return early..
if (empty($tags)) {
return $checksum;
}
$query_tags = array_diff($tags, array_keys($this->tagCache));
if ($query_tags) {
......
......@@ -19,6 +19,12 @@ public function __construct(protected readonly CacheTagsChecksumInterface $check
* {@inheritdoc}
*/
public function getCurrentChecksum(array $tags) {
// If there are no cache tags, there is no checksum to get and the decorated
// method will be a no-op, so don't log anything.
if (empty($tags)) {
return $this->checksumInvalidator->getCurrentChecksum($tags);
}
$start = microtime(TRUE);
$return = $this->checksumInvalidator->getCurrentChecksum($tags);
$stop = microtime(TRUE);
......@@ -46,6 +52,11 @@ public function isValid($checksum, array $tags) {
* {@inheritdoc}
*/
public function invalidateTags(array $tags) {
// If there are no cache tags, there is nothing to invalidate, and the
// decorated method will be a no-op, so don't log anything.
if (empty($tags)) {
return $this->checksumInvalidator->invalidateTags($tags);
}
$start = microtime(TRUE);
$return = $this->checksumInvalidator->invalidateTags($tags);
$stop = microtime(TRUE);
......
......@@ -59,7 +59,7 @@ public function testAnonymous() {
$this->assertSame(137, $performance_data->getCacheGetCount());
$this->assertSame(47, $performance_data->getCacheSetCount());
$this->assertSame(0, $performance_data->getCacheDeleteCount());
$this->assertCountBetween(143, 146, $performance_data->getCacheTagChecksumCount());
$this->assertCountBetween(40, 43, $performance_data->getCacheTagChecksumCount());
$this->assertCountBetween(47, 50, $performance_data->getCacheTagIsValidCount());
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
......@@ -73,7 +73,7 @@ public function testAnonymous() {
$this->assertSame(95, $performance_data->getCacheGetCount());
$this->assertSame(16, $performance_data->getCacheSetCount());
$this->assertSame(0, $performance_data->getCacheDeleteCount());
$this->assertCountBetween(79, 80, $performance_data->getCacheTagChecksumCount());
$this->assertCountBetween(24, 25, $performance_data->getCacheTagChecksumCount());
$this->assertCountBetween(41, 42, $performance_data->getCacheTagIsValidCount());
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
......@@ -87,6 +87,7 @@ public function testAnonymous() {
$this->assertSame(81, $performance_data->getCacheGetCount());
$this->assertSame(16, $performance_data->getCacheSetCount());
$this->assertSame(0, $performance_data->getCacheDeleteCount());
$this->assertCountBetween(24, 25, $performance_data->getCacheTagChecksumCount());
$this->assertCountBetween(36, 37, $performance_data->getCacheTagIsValidCount());
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment