Shortcuts toolbar links are not updated automatically when default shortcut set is changed

Created on 11 March 2024, 10 months ago
Updated 16 April 2024, 8 months ago

Problem/Motivation

When users change their default shortcut set, those changes are not being reflected in the toolbar shortcuts section until cache is cleared.
These changes should be reflected automatically.

Steps to reproduce

Install a default Drupal standard installation
Login as user 1
Click on the toolbar "Shortcuts" icon and check the links included there
Visit /admin/config/user-interface/shortcut and create a new shortcut set
Change the list of links for the new set, adding, removing or editing the links
Visit /user/1/shortcuts and change the default shortcut set to the new one
Once the form is saved, click again on the "Shortcuts" toolbar icon
Links are the ones in the default shortcut set and not the ones in the new one

Proposed resolution

Add logic to invalidate user's selected shortcut set to recalculate it next time the toolbar is generated.

Remaining tasks

Review

User interface changes

None

API changes

Deprecate shortcut_current_displayed_set() and shortcut_default_set(). Add new method to ShortcutSetStorageInterface to replace the former.

Data model changes

None

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

10.3 ✨

Component
ShortcutΒ  β†’

Last updated 3 months ago

  • Maintained by
  • πŸ‡¨πŸ‡¦Canada @jibran
Created by

πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @plopesc
  • Pipeline finished with Failed
    10 months ago
    Total: 174s
    #116398
  • Pipeline finished with Success
    10 months ago
    Total: 555s
    #116403
  • Status changed to Needs review 10 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    MR created

  • Pipeline finished with Failed
    10 months ago
    Total: 602s
    #117400
  • Pipeline finished with Success
    10 months ago
    Total: 2118s
    #117418
  • Status changed to RTBC 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Ran the test-only feature and got failing tests as expected https://git.drupalcode.org/issue/drupal-3427046/-/jobs/1047844

    Change record is present and reads fine.
    Link in MR matches

    Issue summary is complete (thank you for that!)
    Following the steps believe I am seeing the issue.

    Adding the cacheTags appears to be inline with how it's done in other places.

    LGTM!

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've added some comments to the MR. This looks like a nice thing to get fixed.

  • Pipeline finished with Failed
    9 months ago
    Total: 173s
    #128479
  • Pipeline finished with Success
    9 months ago
    Total: 504s
    #128496
  • Status changed to Needs review 9 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Thank you for your review @alexpott.

    I think all the suggested improvements have been implemented properly and the R is ready for a new round of reviews.

  • Status changed to RTBC 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Re-ran test-only feature https://git.drupalcode.org/issue/drupal-3427046/-/jobs/1150296

    Seems coverage is still there. Appears feedback from @alexpott has been addressed.

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Discussed with @catch because I'm not sure about the affect of having a cache tag per user and whether it makes much sense. I think this might end up creating lots and lots of cache entries.

    I think we should be able to invalidate cache by the user's current default shortcut set... ie. by doing something like

        $default = $this->getDefaultSet($account);
        if ($default instanceof ShortcutSet) {
          Cache::invalidateTags($default->getCacheTags());
        }
    

    in assignUser and unassignUser... this is working for assignUser but is not working for unassignUser - yes we will ending clearing more cache when assign and unassign happen - but how often does this occur?

  • Pipeline finished with Failed
    9 months ago
    Total: 177s
    #129299
  • Pipeline finished with Success
    9 months ago
    Total: 589s
    #129305
  • Status changed to Needs review 9 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Thank you for your comment.

    I thought the approach would not affect he number of cache entries, given that we already had the user context, but forgot to take into account the cachetags table, where a new row per tag is added.

    Based on your suggestion, this new approach invalidate the previous set cache tag when assigning a new set or unassigning the current one. This is a bit more aggressive because it invalidates some entries unnecessarily, but maintains the size of cachetags table under control.

    Also , we are not introducing a BC change, so the CR created would not be necessary anymore.

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @plopesc thanks for sticking with this. Cache invalidation of stuff like this is never simple. I agree with your proposal about moving stuff to ShortcutSetStorage and have commented on the MR with some thoughts.

  • Pipeline finished with Failed
    9 months ago
    Total: 167s
    #129593
  • Pipeline finished with Failed
    9 months ago
    Total: 2801s
    #129595
  • Pipeline finished with Success
    9 months ago
    Total: 491s
    #129665
  • Pipeline finished with Success
    9 months ago
    Total: 548s
    #129675
  • Status changed to Needs review 9 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    @alexpott New role for review including the new method ShortcutSetStorage::getDisplayedToUser() and deprecation of shortcut_current_displayed_set() & shortcut_default_set() functions.

    Some followup questions.

    • We are adding new parameters to ShortcutLazyBuilders service and deprecating 2 functions. Can we have both in a single CR? Or we might need 2?
    • shortcut_current_displayed_set() implements the drupal_static() pattern. Do we need to add something special for this? It's being invoked only from ShortcutSetStorage to be refreshed once shortcut sets are being assigned/unassigned or removed.

    Thank you

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    All in one CR is fine because it all goes together in my mind. Also the constructor changes are secondary and should only form a small part of the CR. Added some comments to the MR too.

  • Pipeline finished with Success
    9 months ago
    Total: 506s
    #129732
  • Pipeline finished with Success
    9 months ago
    Total: 489s
    #129743
  • Status changed to Needs review 9 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Feedback has been addressed and CR updated.

    See comment on MR about the need to add static cache to getDisplayedToUser().

    While we're here, would you consider appropriate a follow up issue to provide a shortcut related cache context to avoid having a cache entry per user?. In an scenario where most users have selected the same shortcut_set, most of those cache entries would be redundant.

  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Created πŸ“Œ [PP-1] Remove deprecated code from shortcut module Postponed to keep track of deprecation code that might need to be removed before 11.0.0.

    Also updated IS to reflect the final approach taken.

  • Pipeline finished with Failed
    9 months ago
    Total: 180s
    #133511
  • Pipeline finished with Success
    9 months ago
    Total: 580s
    #133513
  • Status changed to RTBC 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Added some simple typehints to the new function. Rest of the changes look good though

    • catch β†’ committed 26f98e16 on 10.3.x
      Issue #3427046 by plopesc, smustgrave, alexpott: Shortcuts toolbar links...
    • catch β†’ committed 30a1adec on 11.x
      Issue #3427046 by plopesc, smustgrave, alexpott: Shortcuts toolbar links...
  • Status changed to Fixed 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    The new cache invalidation approach looks good to me. I did briefly think about just using the user entity cache tag here, but then we'd potentially be invalidating entity caches for the user when we update their shortcut set which is much more likely to affect things (especially when the user is rendered as part of entities they've created like node/comment author).

    Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Yay, one fewer bit of Shortcut architectural complexity! πŸ‘

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024