From f6312b85d2509bd4fa3e10f17db2b145a3ac4781 Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Fri, 29 Aug 2014 23:11:29 -0700 Subject: [PATCH] Issue #2202185 by Wim Leers, effulgentsia, msonnabaum, damiankloip, alexpott: Statically cache Role entities to speed up (User|UserSession)::hasPermission(). --- core/modules/user/src/Entity/Role.php | 1 + core/modules/user/src/Tests/UserRoleAdminTest.php | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/modules/user/src/Entity/Role.php b/core/modules/user/src/Entity/Role.php index 9eba85912cc1..927b1c80264d 100644 --- a/core/modules/user/src/Entity/Role.php +++ b/core/modules/user/src/Entity/Role.php @@ -28,6 +28,7 @@ * }, * admin_permission = "administer permissions", * config_prefix = "role", + * static_cache = TRUE, * entity_keys = { * "id" = "id", * "weight" = "weight", diff --git a/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php index 3fabdb3bb765..e8e8815f8358 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -53,12 +53,11 @@ function testRoleAdministration() { $this->assertRaw(t('The machine-readable name is already in use. It must be unique.'), 'Duplicate role warning displayed.'); // Test renaming a role. - $old_name = $role_name; $role_name = '456'; $edit = array('label' => $role_name); $this->drupalPostForm("admin/people/roles/manage/{$role->id()}", $edit, t('Save')); $this->assertRaw(t('Role %label has been updated.', array('%label' => $role_name))); - $new_role = entity_load('user_role', $old_name); + $new_role = entity_load('user_role', $role->id(), TRUE); $this->assertEqual($new_role->label(), $role_name, 'The role name has been successfully changed.'); // Test deleting a role. @@ -67,7 +66,7 @@ function testRoleAdministration() { $this->drupalPostForm(NULL, array(), t('Delete')); $this->assertRaw(t('Role %label has been deleted.', array('%label' => $role_name))); $this->assertNoLinkByHref("admin/people/roles/manage/{$role->id()}", 'Role edit link removed.'); - $this->assertFalse(entity_load('user_role', $role_name), 'A deleted role can no longer be loaded.'); + $this->assertFalse(entity_load('user_role', $role->id(), TRUE), 'A deleted role can no longer be loaded.'); // Make sure that the system-defined roles can be edited via the user // interface. -- GitLab