function StandardPerformanceTest::testCacheInvalidation

Tests the impact of a cache tag based invalidation.

1 call to StandardPerformanceTest::testCacheInvalidation()
StandardPerformanceTest::testStandardPerformance in core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php
Tests performance of the standard profile.

File

core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php, line 334

Class

StandardPerformanceTest
Tests the performance of basic functionality in the standard profile.

Namespace

Drupal\Tests\standard\FunctionalJavascript

Code

protected function testCacheInvalidation() : void {
  // Crate a new page, this invalidates the node_list cache tag. Need to reset
  // the cache tag checksum service as it did not register a need to
  // invalidate that again. Repeat this twice as some routing caches are not
  // yet properly populated due to directly emptying the caches before.
  \Drupal::service('cache_tags.invalidator.checksum')->reset();
  $this->drupalCreateNode([
    'type' => 'page',
    'title' => 'new page',
  ]);
  $this->drupalGet('');
  // Ensure everything finishes before we collect performance data.
  $this->drupalGet('');
  sleep(2);
  \Drupal::service('cache_tags.invalidator.checksum')->reset();
  $this->drupalCreateNode([
    'type' => 'page',
    'title' => 'new page',
  ]);
  // Visit the frontpage again.
  $performance_data = $this->collectPerformanceData(function () {
    $this->drupalGet('');
  }, 'standardFrontPageAfterInvalidation');
  $expected_queries = [
    'SELECT COUNT(*) AS "expression" FROM (SELECT 1 AS "expression" FROM "node_field_data" "node_field_data" WHERE ("node_field_data"."promote" = 1) AND ("node_field_data"."status" = 1)) "subquery"',
    'SELECT "node_field_data"."sticky" AS "node_field_data_sticky", "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid" FROM "node_field_data" "node_field_data" WHERE ("node_field_data"."promote" = 1) AND ("node_field_data"."status" = 1) ORDER BY "node_field_data_sticky" DESC, "node_field_data_created" DESC LIMIT 10 OFFSET 0',
    'SELECT "name", "value" FROM "key_value" WHERE "name" IN ( "theme:stark" ) AND "collection" = "config.entity.key_store.block"',
  ];
  $recorded_queries = $performance_data->getQueries();
  $this->assertSame($expected_queries, $recorded_queries);
  $expected = [
    'QueryCount' => 3,
    'CacheGetCount' => 69,
    'CacheGetCountByBin' => [
      'page' => 1,
      'config' => 11,
      'data' => 8,
      'discovery' => 21,
      'bootstrap' => 7,
      'dynamic_page_cache' => 2,
      'render' => 14,
      'default' => 3,
      'entity' => 1,
      'menu' => 1,
    ],
    'CacheSetCount' => 5,
    'CacheSetCountByBin' => [
      'data' => 1,
      'render' => 2,
      'dynamic_page_cache' => 1,
      'page' => 1,
    ],
    'CacheDeleteCount' => 0,
    'CacheTagInvalidationCount' => 0,
    'CacheTagLookupQueryCount' => 3,
    'CacheTagGroupedLookups' => [
      [
        'CACHE_MISS_IF_UNCACHEABLE_HTTP_METHOD:form',
        'block_view',
        'config:block.block.stark_account_menu',
        'config:block.block.stark_breadcrumbs',
        'config:block.block.stark_content',
        'config:block.block.stark_help',
        'config:block.block.stark_main_menu',
        'config:block.block.stark_messages',
        'config:block.block.stark_page_title',
        'config:block.block.stark_powered',
        'config:block.block.stark_primary_admin_actions',
        'config:block.block.stark_primary_local_tasks',
        'config:block.block.stark_search_form_narrow',
        'config:block.block.stark_search_form_wide',
        'config:block.block.stark_secondary_local_tasks',
        'config:block.block.stark_site_branding',
        'config:block_list',
        'config:filter.format.restricted_html',
        'config:search.settings',
        'config:system.menu.account',
        'config:system.menu.main',
        'config:system.site',
        'config:user.role.anonymous',
        'config:views.view.frontpage',
        'http_response',
        'local_task',
        'node:1',
        'node_list',
        'node_view',
        'rendered',
        'user:0',
        'user_view',
      ],
      [
        'route_match',
        'access_policies',
        'routes',
        'router',
        'entity_types',
        'entity_field_info',
        'entity_bundles',
        'library_info',
      ],
      [
        'config:core.extension',
        'views_data',
      ],
    ],
    'StylesheetCount' => 1,
    'StylesheetBytes' => 1300,
  ];
  $this->assertMetrics($expected, $performance_data);
  $expected_default_cache_cids = [
    'views_data:node_field_data:en',
    'views_data:views:en',
    'views_data:node:en',
  ];
  $this->assertSame($expected_default_cache_cids, $performance_data->getCacheOperations()['get']['default']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.