From 6ffc61f5afd834e8294cd94be492f770d4a50b68 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Wed, 4 Mar 2015 16:38:46 +0000 Subject: [PATCH] Issue #2443485 by Berdir, dawehner: Remove extension:views cache tag and other views related cache improvements --- core/includes/module.inc | 10 ---------- .../comment/src/Plugin/views/argument/UserUid.php | 2 +- .../comment/src/Plugin/views/filter/UserUid.php | 2 +- .../src/Tests/Views/ArgumentUserUIDTest.php | 15 +++++++++++++++ .../comment/src/Tests/Views/FilterUserUIDTest.php | 15 +++++++++++++++ .../views/src/Plugin/ViewsHandlerManager.php | 2 +- .../views/src/Plugin/ViewsPluginManager.php | 2 +- .../Plugin/views/display/DisplayPluginBase.php | 2 +- core/modules/views/src/Tests/DefaultViewsTest.php | 2 -- .../views/src/Tests/Entity/FieldEntityTest.php | 2 -- .../Tests/Entity/ViewEntityDependenciesTest.php | 2 -- core/modules/views/src/Tests/FieldApiDataTest.php | 2 -- .../src/Tests/Handler/FieldGroupRowsTest.php | 2 -- core/modules/views/src/Tests/ViewTestBase.php | 5 ----- core/modules/views/src/ViewsData.php | 2 +- core/modules/views/views.module | 12 +++--------- 16 files changed, 39 insertions(+), 40 deletions(-) diff --git a/core/includes/module.inc b/core/includes/module.inc index 642c32c6d0b2..f65f0b877ff5 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -60,16 +60,6 @@ function system_list_reset() { drupal_static_reset('system_list'); drupal_static_reset('system_rebuild_module_data'); \Drupal::cache('bootstrap')->delete('system_list'); - - // Clear the library info cache. - // Libraries may be provided by all extension types, and may be altered by any - // other extensions (types) due to the nature of - // \Drupal\Core\Extension\ModuleHandler::alter() and the fact that profiles - // are recorded and handled as modules. - // @todo Trigger an event upon module install/uninstall and theme - // enable/disable, and move this into an event subscriber. - // @see https://drupal.org/node/2206347 - Cache::invalidateTags(['config:core.extension']); } /** diff --git a/core/modules/comment/src/Plugin/views/argument/UserUid.php b/core/modules/comment/src/Plugin/views/argument/UserUid.php index 77ed0cc0fad4..7025f12ee59d 100644 --- a/core/modules/comment/src/Plugin/views/argument/UserUid.php +++ b/core/modules/comment/src/Plugin/views/argument/UserUid.php @@ -87,7 +87,7 @@ public function query($group_by = FALSE) { // Use the table definition to correctly add this user ID condition. if ($this->table != 'comment') { - $subselect = $this->database->select('comment', 'c'); + $subselect = $this->database->select('comment_field_data', 'c'); $subselect->addField('c', 'cid'); $subselect->condition('c.uid', $this->argument); diff --git a/core/modules/comment/src/Plugin/views/filter/UserUid.php b/core/modules/comment/src/Plugin/views/filter/UserUid.php index ebef422ef4ca..16d4fb030321 100644 --- a/core/modules/comment/src/Plugin/views/filter/UserUid.php +++ b/core/modules/comment/src/Plugin/views/filter/UserUid.php @@ -22,7 +22,7 @@ class UserUid extends FilterPluginBase { public function query() { $this->ensureMyTable(); - $subselect = db_select('comment', 'c'); + $subselect = db_select('comment_field_data', 'c'); $subselect->addField('c', 'cid'); $subselect->condition('c.uid', $this->value, $this->operator); diff --git a/core/modules/comment/src/Tests/Views/ArgumentUserUIDTest.php b/core/modules/comment/src/Tests/Views/ArgumentUserUIDTest.php index 9b0ed7f108c3..337135881f17 100644 --- a/core/modules/comment/src/Tests/Views/ArgumentUserUIDTest.php +++ b/core/modules/comment/src/Tests/Views/ArgumentUserUIDTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests\Views; +use Drupal\comment\Entity\Comment; +use Drupal\user\Entity\User; use Drupal\views\Views; /** @@ -24,6 +26,19 @@ class ArgumentUserUIDTest extends CommentTestBase { public static $testViews = array('test_comment_user_uid'); function testCommentUserUIDTest() { + // Add an additional comment which is not created by the user. + $new_user = User::create(['name' => 'new user']); + $new_user->save(); + + $comment = Comment::create([ + 'uid' => $new_user->uid->value, + 'entity_id' => $this->nodeUserCommented->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + 'subject' => 'if a woodchuck could chuck wood.', + ]); + $comment->save(); + $view = Views::getView('test_comment_user_uid'); $this->executeView($view, array($this->account->id())); $result_set = array( diff --git a/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php b/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php index b2fe796138b3..ffee1d10b3f6 100644 --- a/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php +++ b/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests\Views; +use Drupal\comment\Entity\Comment; +use Drupal\user\Entity\User; use Drupal\views\Views; /** @@ -30,6 +32,19 @@ function testCommentUserUIDTest() { $view->setDisplay(); $view->removeHandler('default', 'argument', 'uid_touch'); + // Add an additional comment which is not created by the user. + $new_user = User::create(['name' => 'new user']); + $new_user->save(); + + $comment = Comment::create([ + 'uid' => $new_user->uid->value, + 'entity_id' => $this->nodeUserCommented->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + 'subject' => 'if a woodchuck could chuck wood.', + ]); + $comment->save(); + $options = array( 'id' => 'uid_touch', 'table' => 'node_field_data', diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index b6aa487c7a34..5244147d9777 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -59,7 +59,7 @@ public function __construct($handler_type, \Traversable $namespaces, ViewsData $ } parent::__construct("Plugin/views/$handler_type", $namespaces, $module_handler, $plugin_interface, $plugin_definition_annotation_name); - $this->setCacheBackend($cache_backend, "views:$handler_type", array('config:core.extension', 'extension:views')); + $this->setCacheBackend($cache_backend, "views:$handler_type"); $this->alterInfo('views_plugins_' . $handler_type); $this->viewsData = $views_data; diff --git a/core/modules/views/src/Plugin/ViewsPluginManager.php b/core/modules/views/src/Plugin/ViewsPluginManager.php index efb9061fcffe..97d41c7c9956 100644 --- a/core/modules/views/src/Plugin/ViewsPluginManager.php +++ b/core/modules/views/src/Plugin/ViewsPluginManager.php @@ -43,7 +43,7 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa ); $this->alterInfo('views_plugins_' . $type); - $this->setCacheBackend($cache_backend, "views:$type", array('config:core.extension', 'extension:views')); + $this->setCacheBackend($cache_backend, "views:$type"); } } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 835c10694991..37c297d1244c 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -186,7 +186,7 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio } else { $this->unpackOptions($this->options, $options); - \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, Cache::mergeTags(array('config:core.extension', 'extension:views'), $this->view->storage->getCacheTags())); + \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, $this->view->storage->getCacheTags()); } static::$unpackOptions[$cid] = $this->options; } diff --git a/core/modules/views/src/Tests/DefaultViewsTest.php b/core/modules/views/src/Tests/DefaultViewsTest.php index 27f0d8bb85e5..1d1186872d0e 100644 --- a/core/modules/views/src/Tests/DefaultViewsTest.php +++ b/core/modules/views/src/Tests/DefaultViewsTest.php @@ -86,8 +86,6 @@ protected function setUp() { $this->addDefaultCommentField('node', 'page'); - $this->container->get('views.views_data')->clear(); - for ($i = 0; $i <= 10; $i++) { $user = $this->drupalCreateUser(); $term = $this->createTerm($vocabulary); diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/src/Tests/Entity/FieldEntityTest.php index acc7680be893..37e27c0bc21b 100644 --- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php +++ b/core/modules/views/src/Tests/Entity/FieldEntityTest.php @@ -45,8 +45,6 @@ public function testGetEntity() { $account->save(); $this->drupalCreateContentType(array('type' => 'page')); $this->addDefaultCommentField('node', 'page'); - // Force a flush of the in-memory storage. - $this->container->get('views.views_data')->clear(); $node = entity_create('node', array('uid' => $account->id(), 'type' => 'page')); $node->save(); diff --git a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php index 44930ed552ff..cee903e443ec 100644 --- a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php +++ b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php @@ -81,8 +81,6 @@ public function testCalculateDependencies() { 'label' => $this->randomMachineName() . '_body', 'settings' => array('display_summary' => TRUE), ))->save(); - // Force a flush of the in-memory storage. - $this->container->get('views.views_data')->clear(); $expected = []; $expected['test_field_get_entity'] = [ diff --git a/core/modules/views/src/Tests/FieldApiDataTest.php b/core/modules/views/src/Tests/FieldApiDataTest.php index 31c73ad85367..e0630d1ab11c 100644 --- a/core/modules/views/src/Tests/FieldApiDataTest.php +++ b/core/modules/views/src/Tests/FieldApiDataTest.php @@ -36,8 +36,6 @@ protected function setUp() { ); $nodes[] = $this->drupalCreateNode($edit); } - - $this->container->get('views.views_data')->clear(); } /** diff --git a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php index bcccbdc1ebfc..a5f18d225a80 100644 --- a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php @@ -61,8 +61,6 @@ protected function setUp() { 'bundle' => $node_type->id(), ); entity_create('field_config', $field)->save(); - - $this->container->get('views.views_data')->clear(); } /** diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php index 042c5cec55e0..d0bc9890760c 100644 --- a/core/modules/views/src/Tests/ViewTestBase.php +++ b/core/modules/views/src/Tests/ViewTestBase.php @@ -34,11 +34,6 @@ abstract class ViewTestBase extends WebTestBase { protected function setUp($import_test_views = TRUE) { parent::setUp(); - - // Ensure that the plugin definitions are cleared. - foreach (ViewExecutable::getPluginTypes() as $plugin_type) { - $this->container->get("plugin.manager.views.$plugin_type")->clearCachedDefinitions(); - } if ($import_test_views) { ViewTestData::createTestViews(get_class($this), array('views_test_config')); } diff --git a/core/modules/views/src/ViewsData.php b/core/modules/views/src/ViewsData.php index 81469e7724dd..2c8fe2351541 100644 --- a/core/modules/views/src/ViewsData.php +++ b/core/modules/views/src/ViewsData.php @@ -200,7 +200,7 @@ protected function cacheGet($cid) { * The data that will be cached. */ protected function cacheSet($cid, $data) { - return $this->cacheBackend->set($this->prepareCid($cid), $data, Cache::PERMANENT, array('views_data', 'config:core.extension', 'extension:views')); + return $this->cacheBackend->set($this->prepareCid($cid), $data, Cache::PERMANENT, array('views_data', 'config:core.extension')); } /** diff --git a/core/modules/views/views.module b/core/modules/views/views.module index d8516be19a9f..319762255e86 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -462,33 +462,27 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable * Implements hook_ENTITY_TYPE_create() for 'field_config'. */ function views_field_config_create(FieldConfigInterface $field) { - // @todo: Is this necessary? Use cache tags to only delete Views' cache data? - \Drupal::cache('discovery')->deleteAll(); + Views::viewsData()->clear(); } /** * Implements hook_ENTITY_TYPE_update() for 'field_config'. */ function views_field_config_update(FieldConfigInterface $field) { - Cache::invalidateTags(['extension:views']); - \Drupal::cache('render')->deleteAll(); + Views::viewsData()->clear(); } /** * Implements hook_ENTITY_TYPE_delete() for 'field_config'. */ function views_field_config_delete(FieldConfigInterface $field) { - Cache::invalidateTags(['extension:views']); - \Drupal::cache('render')->deleteAll(); + Views::viewsData()->clear(); } /** * Invalidate the views cache, forcing a rebuild on the next grab of table data. */ function views_invalidate_cache() { - // Clear Views' info cache entries. - Cache::invalidateTags(['extension:views']); - // Set the menu as needed to be rebuilt. \Drupal::service('router.builder_indicator')->setRebuildNeeded(); -- GitLab