Problem/Motivation

When the SectorTocBlock block and TocChunkerFormatter field formatter are rendered on the same page they both make a call to TocManager to create a table of contents with the same field data.

TocManager statically caches the ToC - but we are not retrieving this at any point and end up initializing the same field value twice. This can be expensive when dealing with content that has a lot of elements.

Proposed resolution

Use the same id in the block and field formatted so an existing ToC can be reused if either has initialized it already.

The key should be unique to the node being rendered and the type of toc being generated (for reference - the module currently hard codes sector_toc in the toc block, but allows any toc to be configured in the field formatter. If these are different, then they should not share the same toc instance).

Issue fork sector_toc-3468455

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

ericgsmith created an issue. See original summary.

ericgsmith’s picture

Will think about tests over the weekend

ericgsmith’s picture

Status: Active » Needs review

Was hoping to make a simple unit test but mocking the field formatter was painful.

Test only changes pipeline shows:

> Failed asserting that actual size 2 matches expected size 1.

Think it is worth adding a proper functional js text to cover everything in this module - but this should be a OK start for this improvement.

ericgsmith’s picture

Assigned: ericgsmith » Unassigned
ericgsmith’s picture

Issue summary: View changes

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

  • rosk0 committed a164270c on 1.x authored by ericgsmith
    Issue #3468455 by ericgsmith: Share toc id between TocChunkerFormatter...
rosk0’s picture

Status: Needs review » Fixed

Thanks Eric!

Status: Fixed » Closed (fixed)

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