Problem/Motivation

If you install this module with the Mercury theme and visit different 404 pages you will get a dynamic page cache entry page per 404.

Steps to reproduce

  • Install Mercury Theme and Easy Breadcrumb
  • Visit pages that would result in 404
  • Watch rows grow in cache_dynamic_page_cache

Proposed resolution

Not sure. Core's path based breadcrumb builder uses

    // Add the url.path.parent cache context. This code ignores the last path
    // part so the result only depends on the path parents.
    $breadcrumb->addCacheContexts(['url.path.parent', 'url.path.is_front']);

But given in default configuration to add the current page title to breadcrumb I don't think that is would work.

Also you can't add a reponse status cache to breadcromb block because that also adds a url.path to cache context. There might be a core issue here for how url.path works with 404s and 403s.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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

alexpott created an issue. See original summary.

alexpott’s picture

catch’s picture

Opened #3516173: Block status code visibility condition should use a status code cache context to core, but just that issue would require sites to configure the breadcrumb block not to show on 404 pages.

However once the cache context is there, it might be possible to check for a 404/403 first, early return there while adding the status code cache context, then only add the url cache context if it gets past that. Or set the breadcrumb builder not to apply on 404 pages at all.

greg boggs’s picture

I had noticed this problem on my own Drupal website, and didn't realize it was easy breadcrumb module doing it.

This cache improvement sounds fantastic. Hiding breadcrumbs on 404 also sounds good. If y'all want to just look over the cache code and make sure it's correct that would be ideal. The cache code is grouped in the module here:

https://git.drupalcode.org/project/easy_breadcrumb/-/blob/2.x/src/EasyBr...

I think this is an unrelated cache issue:
https://www.drupal.org/project/easy_breadcrumb/issues/3500483

catch’s picture

So #3516173: Block status code visibility condition should use a status code cache context will make the performance issue fixable with the status code block condition.

But I think it would be good to fix this directly in easy breadcrumb too - it can look for the exception on the request (see code in that issue), and if it's there, early return and only add the status code cache context instead of the URL one - probably best to do in the ::applies() method? Not familiar with the code so take with a pinch of salt but should be enough to get started. Only problem is that cache context will be in 11.2, maybe 10.5, but not a patch release, so either needs to wait or maybe copy it for a while.

greg boggs’s picture

Makes sense. I'll see what I can do. That code is pretty messy at this point after many years of small public contributions.

yonailo’s picture

Hello,

Any movement on this ? We are experiencing enormous "cache_dynamic_page" table sizes and I am wondering if it could be related to this issue, we have a lot of bots trying 404 pages at random.

greg boggs’s picture

Not yet! As a temporary fix, you can exclude the breadcrumb block from 404 pages.

yonailo’s picture

I’ve been doing some debugging with my client’s site and I don’t understand what is happening.

It seems that the dynamic cache grows because the breadcrumb block has a visibility condition with path != front_page

This makes all 404 pages to create a dynamic cache entry that includes the path.url context.

If I remove this visibility condition, the dynamic cache does not grow, which I don’t understand because I see that the breadcrumb builder is adding path.url …

loopduplicate made their first commit to this issue’s fork.

loopduplicate’s picture

Assigned: Unassigned » loopduplicate

loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Issue summary: View changes
Status: Active » Needs review
Issue tags: +page cache, +Drupal CMS
loopduplicate’s picture

Assigned: Unassigned » loopduplicate
Status: Needs review » Active

Well, as I expected before I went to sleep last night, the code I wrote was going to crash d10. Tested this morning. I was right. So, more work is needed for sure.

loopduplicate’s picture

Issue summary: View changes
loopduplicate’s picture

Issue summary: View changes

loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Active » Needs review

OK, tested on d10 and d11. Ready for review again with a new MR.

loopduplicate’s picture

Issue summary: View changes
catch’s picture

loopduplicate changed the visibility of the branch 3516169-exception-cache-context to hidden.

loopduplicate changed the visibility of the branch 3516169-exception-cache-context to active.

loopduplicate changed the visibility of the branch 3516169-exception-cache-context to hidden.

loopduplicate’s picture

Assigned: Unassigned » loopduplicate
Status: Needs review » Active

I'm working on writing a test for this now.

loopduplicate’s picture

Assigned: loopduplicate » Unassigned

I've added a test. The problem for me is that this bug is not reproducible except when using Drupal CMS. So, with just this module enabled, the test passes even before the chanages I made while working on this issue. So, I'm trying to figure out exactly what combination of modules and config can make this happen so I can get a failing test here.

loopduplicate’s picture

This bug is not reproducible when choosing the Blank site template.
It is reproducible with the Starter and the Mercury Demo.

loopduplicate’s picture

As far as I can tell, it's the Mercury theme combined with Easy Breadcrumb that is causing the cache to grow.

loopduplicate changed the visibility of the branch 3516169-exception-cache-context-27 to hidden.

loopduplicate’s picture

Issue summary: View changes
Status: Active » Needs review

OK! Good progress.
I've created a test that installs the Mercury theme to reproduce this bug!
Then, I applied the code fix I wrote earlier in this issue.
It's all in the new MR, and pretty easy to understand.
Excited to see what people think and if we can get this reviewed.

Peace.

loopduplicate’s picture

Issue summary: View changes

loopduplicate’s picture

Assigned: Unassigned » loopduplicate
Status: Needs review » Active

Well, I rerolled this after #3500483 was committed. Since we now set cache contexts in the applies() method, the code from MR!188 no longer works. I'll work on a solution. The good news is that the test I wrote failed and that's how I knew the code didn't work anymore. +1 for TDD, eh?

loopduplicate changed the visibility of the branch 3516169-exception-cache-context-34 to active.

loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Active » Needs review

Ok, tests pass again. The change was to remove the 'url' cache context in the applies() method. When all versions of core that are supported by this module support adding cacheable metadata in the applies() method, we can refactor.

loopduplicate’s picture

Assigned: Unassigned » loopduplicate
Status: Needs review » Active

I'm working on this now to get it working with the current 2.x version again. It would have been nice to get this in the release yesterday, but it will have to wait until the next one now.

  • loopduplicate committed bbeca29a on 3516169-exception-cache-context-39
    Issue #3516169 Fixes caching bug for exception pages.
    

loopduplicate changed the visibility of the branch 3516169-exception-cache-context-34 to hidden.

loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Active » Needs review

OK, all set and up to date with the latest changes. Ready for review again.

greg boggs’s picture

Test results:
- Reverted just the fix code (kept MR's new regression test EasyBreadcrumbDynamicPageCacheTest) - test failed, table grew 4→5 rows on a second distinct 404, reproducing the bug exactly as described.
- Restored the MR's fix - same test passed, row count stayed flat across multiple 404s.

MR 228 does fix what issue 3516169 claims it fixes.

Manual testing revealed nothing unusual in caching or the breadcrumbs

---
Disclosure: AI was used in assisting to test this issue.

greg boggs’s picture

Status: Needs review » Reviewed & tested by the community
loopduplicate’s picture

Assigned: Unassigned » loopduplicate

Great Greg! I'll work on getting this merged in now.

  • loopduplicate committed 68021db2 on 2.x
    Fix: #3516169 Adds caching logic for exception pages.
    
    Fixes: Adding url...
loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Reviewed & tested by the community » Fixed

Thanks! @alexpott, @catch, @greg boggs, @yonailo

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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