Skip to content
Snippets Groups Projects

Issue #3437576: Provide a new user.shortcut_set cache context

Open Issue #3437576: Provide a new user.shortcut_set cache context
6 unresolved threads
6 unresolved threads

Closes #3437576

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
64 $this->user = User::create([
65 'name' => 'first',
66 'mail' => 'first@example.com',
67 ]);
68 $this->user->save();
69
70 $this->entityTypeManager = \Drupal::entityTypeManager();
71 }
72
73 /**
74 * Tests cache context behavior depending on shortcut set assignments.
75 *
76 * @covers ::getContext
77 * @covers ::getCacheableMetadata
78 */
79 public function testCacheContext() {
  • 33 */
    34 public static function getLabel() {
    35 return t("User's shortcut set");
    36 }
    37
    38 /**
    39 * {@inheritdoc}
    40 */
    41 public function getContext() {
    42 return $this->displayedShortcutSet()->id();
    43 }
    44
    45 /**
    46 * {@inheritdoc}
    47 */
    48 public function getCacheableMetadata() {
  • 26 */
    27 public function __construct(AccountInterface $user, protected EntityTypeManagerInterface $entityTypeManager) {
    28 parent::__construct($user);
    29 }
    30
    31 /**
    32 * {@inheritdoc}
    33 */
    34 public static function getLabel() {
    35 return t("User's shortcut set");
    36 }
    37
    38 /**
    39 * {@inheritdoc}
    40 */
    41 public function getContext() {
  • 19 /**
    20 * Constructs a new UserShortcutSetCacheContext service.
    21 *
    22 * @param \Drupal\Core\Session\AccountInterface $user
    23 * The current user.
    24 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
    25 * The entity type manager.
    26 */
    27 public function __construct(AccountInterface $user, protected EntityTypeManagerInterface $entityTypeManager) {
    28 parent::__construct($user);
    29 }
    30
    31 /**
    32 * {@inheritdoc}
    33 */
    34 public static function getLabel() {
  • added 1 commit

    • 3289ebee - Apply 3 suggestion(s) to 2 file(s)

    Compare with previous version

  • catch @catch started a thread on the diff
  • 44
    45 /**
    46 * {@inheritdoc}
    47 */
    48 public function getCacheableMetadata(): CacheableMetadata {
    49 return (new CacheableMetadata())->addCacheableDependency($this->displayedShortcutSet());
    50 }
    51
    52 /**
    53 * Gets the user's shortcut set displayed.
    54 *
    55 * @return \Drupal\shortcut\ShortcutSetInterface
    56 * The user's shortcut set displayed.
    57 */
    58 protected function displayedShortcutSet(): ShortcutSetInterface {
    59 return $this->entityTypeManager
    • Maintainer

      At the moment, the per-user render cache means that the database query and/or hook implementations in ShortcutSetStorage::getDisplayedToUser() are cached behind the render cache.

      This will result in more efficient caching, but it will also mean that logic running on every page. Would it be worth adding caching to ::getDisplayedToUser() too? It would be a much smaller cache item than the render array, so still less to store overall, but would mean no extra database query.

    • Please register or sign in to reply
  • catch @catch started a thread on the diff
  • 89 88 * {@inheritdoc}
    90 89 */
    91 90 public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
    92 $current_shortcut_set = $this->getDisplayedToUser($account);
    Please register or sign in to reply
    Loading