function NodePerformanceTest::testPromotedContentCacheInvalidation
Tests the impact of node cache invalidation on the promoted content view.
File
-
core/
modules/ node/ tests/ src/ FunctionalJavascript/ NodePerformanceTest.php, line 199
Class
- NodePerformanceTest
- Tests the performance of node functionality including cache invalidation.
Namespace
Drupal\Tests\node\FunctionalJavascriptCode
protected function testPromotedContentCacheInvalidation() : void {
// Create a new node, 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.
\Drupal::service('cache_tags.invalidator.checksum')->reset();
$this->drupalCreateNode([
'type' => 'test_content',
'title' => 'new page 2',
]);
// Visit the promoted content page again.
$performance_data = $this->collectPerformanceData(function () {
$this->drupalGet('node');
}, 'nodePromotedContentAfterInvalidation');
$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',
];
$recorded_queries = $performance_data->getQueries();
$this->assertSame($expected_queries, $recorded_queries);
$expected = [
'QueryCount' => 2,
'CacheGetCount' => 57,
'CacheGetCountByBin' => [
'page' => 1,
'config' => 10,
'data' => 3,
'discovery' => 20,
'bootstrap' => 8,
'dynamic_page_cache' => 2,
'render' => 6,
'default' => 3,
'routes' => 3,
'entity' => 1,
],
'CacheSetCount' => 5,
'CacheSetCountByBin' => [
'data' => 1,
'render' => 2,
'dynamic_page_cache' => 1,
'page' => 1,
],
'CacheDeleteCount' => 0,
'CacheTagInvalidationCount' => 0,
'CacheTagLookupQueryCount' => 3,
'CacheTagGroupedLookups' => [
[
'config:filter.format.plain_text',
'config:user.role.anonymous',
'config:views.view.promoted_content',
'http_response',
'node:1',
'node_list',
'node_view',
'rendered',
'user:0',
'user_view',
],
[
'route_match',
'access_policies',
'routes',
'router',
'entity_types',
'entity_field_info',
'entity_bundles',
'local_task',
'library_info',
],
[
'config:core.extension',
'views_data',
],
],
'StylesheetCount' => 2,
'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.