Problem/Motivation
PromoBarBlock::build() filters bars by the current user's roles and by the request time against start_date/end_date, but its cacheability covers neither:
- Roles: user.roles is missing from the cache contexts, so a bar restricted to one role is cached and served to all visitors, or a missing bar stays missing.
- Dates: there's no max-age, so a scheduled bar doesn't appear at its start date, and an expired one keeps showing until another cache clear.
- Countdown: whether a countdown is attached depends on the request time too.
Steps to reproduce
1. Create a bar restricted to the "authenticated" role.
2. Load a page as an authenticated user, then load it again as anonymous.
3. Result: the anonymous visitor sees the bar.
4. Create a bar with start_date 5 minutes from now and load the page.
5. Wait 5 minutes and load the page again.
6. Result: the bar doesn't appear.
Proposed resolution
- Add the user.roles cache context.
- Set max-age to the seconds until the nearest future start_date, end_date or countdown_date among the store's enabled bars, including bars not yet started.
- Keep the current list cache tags.
Remaining tasks
- MR
- Kernel tests for the contexts and the max-age
User interface changes
API changes
Data model changes
Issue fork commerce_promo_bar-3631080
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
valicComment #3
valicwrong title
Comment #5
valic