Commit e7110263 authored by catch's avatar catch
Browse files

Issue #3553219 by berdir, catch, nicxvan: Remove persistent views:unpack_options caching

(cherry picked from commit a67613e5)
parent 7aeffa40
Loading
Loading
Loading
Loading
Loading
+1 −22
Original line number Diff line number Diff line
@@ -110,13 +110,6 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
   */
  protected $usesAreas = TRUE;

  /**
   * Static cache for unpackOptions, but not if we are in the UI.
   *
   * @var array
   */
  protected static $unpackOptions = [];

  /**
   * The display information coming directly from the view entity.
   *
@@ -198,21 +191,7 @@ public function initDisplay(ViewExecutable $view, array &$display, ?array &$opti
      unset($options['defaults']);
    }

    $cid = 'views:unpack_options:' . hash('sha256', serialize([$this->options, $options])) . ':' . \Drupal::languageManager()->getCurrentLanguage()->getId();
    if (empty(static::$unpackOptions[$cid])) {
      $cache = \Drupal::cache('data')->get($cid);
      if (!empty($cache->data)) {
        $this->options = $cache->data;
      }
      else {
    $this->unpackOptions($this->options, $options);
        \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, $this->view->storage->getCacheTags());
      }
      static::$unpackOptions[$cid] = $this->options;
    }
    else {
      $this->options = static::$unpackOptions[$cid];
    }

    // Mark the view as changed so the user has a chance to save it.
    if ($changed) {
+4 −4
Original line number Diff line number Diff line
@@ -129,22 +129,22 @@ protected function doTestNodePageAdministrator(): void {

    $expected = [
      'QueryCount' => 418,
      'CacheGetCount' => 466,
      'CacheGetCount' => 422,
      'CacheGetCountByBin' => [
        'config' => 156,
        'bootstrap' => 16,
        'discovery' => 107,
        'data' => 67,
        'data' => 23,
        'entity' => 25,
        'dynamic_page_cache' => 1,
        'default' => 31,
        'render' => 39,
        'menu' => 24,
      ],
      'CacheSetCount' => 449,
      'CacheSetCount' => 405,
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 51,
      'CacheTagLookupQueryCount' => 32,
      'ScriptCount' => 3,
      'ScriptBytes' => 198900,
      'StylesheetCount' => 8,
+5 −5
Original line number Diff line number Diff line
@@ -53,10 +53,10 @@ protected function testFrontPageColdCache(): void {

    $expected = [
      'QueryCount' => 336,
      'CacheGetCount' => 436,
      'CacheSetCount' => 430,
      'CacheGetCount' => 392,
      'CacheSetCount' => 386,
      'CacheDeleteCount' => 0,
      'CacheTagLookupQueryCount' => 49,
      'CacheTagLookupQueryCount' => 30,
      'CacheTagInvalidationCount' => 0,
      'ScriptCount' => 1,
      'ScriptBytes' => 12000,
@@ -123,11 +123,11 @@ protected function testFrontPageCoolCache(): void {

    $expected = [
      'QueryCount' => 103,
      'CacheGetCount' => 237,
      'CacheGetCount' => 225,
      'CacheSetCount' => 89,
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 31,
      'CacheTagLookupQueryCount' => 26,
      'ScriptCount' => 1,
      'ScriptBytes' => 12000,
      'StylesheetCount' => 2,
+9 −11
Original line number Diff line number Diff line
@@ -56,9 +56,9 @@ protected function testNodePageColdCache(): void {

    $expected = [
      'QueryCount' => 345,
      'CacheSetCount' => 405,
      'CacheSetCount' => 361,
      'CacheDeleteCount' => 0,
      'CacheTagLookupQueryCount' => 45,
      'CacheTagLookupQueryCount' => 26,
      'CacheTagInvalidationCount' => 0,
      'ScriptCount' => 1,
      'ScriptBytes' => 12000,
@@ -118,11 +118,11 @@ protected function testNodePageCoolCache(): void {

    $expected = [
      'QueryCount' => 110,
      'CacheGetCount' => 214,
      'CacheGetCount' => 208,
      'CacheSetCount' => 64,
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 25,
      'CacheTagLookupQueryCount' => 22,
      'ScriptCount' => 1,
      'ScriptBytes' => 12000,
      'StylesheetCount' => 2,
@@ -250,13 +250,13 @@ protected function testNodePageWarmCache(): void {

    $expected = [
      'QueryCount' => 91,
      'CacheGetCount' => 206,
      'CacheGetCount' => 200,
      'CacheGetCountByBin' => [
        'page' => 1,
        'config' => 66,
        'bootstrap' => 12,
        'discovery' => 67,
        'data' => 12,
        'data' => 6,
        'entity' => 21,
        'dynamic_page_cache' => 1,
        'render' => 21,
@@ -266,7 +266,7 @@ protected function testNodePageWarmCache(): void {
      'CacheSetCount' => 42,
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 25,
      'CacheTagLookupQueryCount' => 22,
      'CacheTagGroupedLookups' => [
        [
          'entity_types',
@@ -279,9 +279,8 @@ protected function testNodePageWarmCache(): void {
          'local_task',
          'library_info',
        ],
        ['config:views.view.related_recipes'],
        ['config:core.extension', 'views_data'],
        ['node:10', 'node:3', 'node:6', 'node:7', 'node_list'],
        ['config:views.view.related_recipes', 'node:10', 'node:3', 'node:6', 'node:7', 'node_list'],
        ['breakpoints'],
        [
          'config:core.entity_view_display.media.image.responsive_3x2',
@@ -311,7 +310,6 @@ protected function testNodePageWarmCache(): void {
          'taxonomy_term:22',
          'taxonomy_term:31',
        ],
        ['config:views.view.recipe_collections'],
        [
          'CACHE_MISS_IF_UNCACHEABLE_HTTP_METHOD:form',
          'block_view',
@@ -355,6 +353,7 @@ protected function testNodePageWarmCache(): void {
          'file:37',
          'media:19',
          'config:system.menu.main',
          'config:views.view.recipe_collections',
          'taxonomy_term:1',
          'taxonomy_term:10',
          'taxonomy_term:11',
@@ -372,7 +371,6 @@ protected function testNodePageWarmCache(): void {
          'taxonomy_term:9',
          'taxonomy_term_list',
        ],
        ['config:views.view.recipes'],
        ['node:1:revisions'],
        ['content_moderation_state:1:revisions'],
        ['config:workflows.workflow.editorial'],
+8 −9
Original line number Diff line number Diff line
@@ -137,11 +137,11 @@ protected function testAnonymous(): void {
    $this->assertSame($expected_queries, $recorded_queries);
    $expected = [
      'QueryCount' => 41,
      'CacheGetCount' => 100,
      'CacheGetCount' => 97,
      'CacheGetCountByBin' => [
        'page' => 1,
        'config' => 20,
        'data' => 8,
        'data' => 5,
        'discovery' => 37,
        'bootstrap' => 10,
        'dynamic_page_cache' => 1,
@@ -153,7 +153,7 @@ protected function testAnonymous(): void {
      'CacheSetCount' => 45,
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 16,
      'CacheTagLookupQueryCount' => 15,
      'CacheTagGroupedLookups' => [
        [
          'route_match',
@@ -166,9 +166,8 @@ protected function testAnonymous(): void {
          'local_task',
          'library_info',
        ],
        ['config:views.view.frontpage'],
        ['config:core.extension', 'views_data'],
        ['node:1', 'node_list'],
        ['config:views.view.frontpage', 'node:1', 'node_list'],
        ['rendered', 'user:0', 'user_view'],
        ['config:filter.format.restricted_html', 'node_view'],
        [
@@ -360,11 +359,11 @@ protected function testCacheInvalidation(): void {
    $this->assertSame($expected_queries, $recorded_queries);
    $expected = [
      'QueryCount' => 3,
      'CacheGetCount' => 70,
      'CacheGetCount' => 67,
      'CacheGetCountByBin' => [
        'page' => 1,
        'config' => 11,
        'data' => 8,
        'data' => 5,
        'discovery' => 21,
        'bootstrap' => 8,
        'dynamic_page_cache' => 2,
@@ -599,11 +598,11 @@ protected function testLoginBlock(): void {
    $this->assertSame($expected_queries, $recorded_queries);
    $expected = [
      'QueryCount' => 18,
      'CacheGetCount' => 107,
      'CacheGetCount' => 104,
      'CacheSetCount' => 1,
      'CacheDeleteCount' => 1,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 20,
      'CacheTagLookupQueryCount' => 19,
    ];
    $this->assertMetrics($expected, $performance_data);
  }