The default configuration of the oEmbed source plugin makes pages uncacheable

Created on 21 March 2024, 9 months ago
Updated 29 May 2024, 7 months ago

Problem/Motivation

To avoid performance issues, allow tokens in oEmbed thumbnail paths Fixed added a date token ([date:custom:Y-m]) to the thumbnails_directory default configuration of the oEmbed source. However, whenever a date token is used without specifying a default replacement value for it, system_tokens() makes the page uncacheable:

    if (empty($data['date'])) {
      $date = \Drupal::time()->getRequestTime();
      // We depend on the current request time, so the tokens are not cacheable
      // at all.
      $bubbleable_metadata->setCacheMaxAge(0);
    }

Steps to reproduce

If you enable cache header debugging and execute this code in a render context (e.g. any Drupal page that displays the thumbnail of an oembed:video media), you will get the x-drupal-dynamic-cache: UNCACHEABLE header.

$media_type = $this->createMediaType('oembed:video');
$source = $media_type->getSource();
$source->getMetadata($media, 'thumbnail_uri')

Proposed resolution

Pass the media entity creation date as additional data for token replacement in \Drupal\media\Plugin\media\Source\OEmbed::getLocalThumbnailUri().

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

Nope.

🐛 Bug report
Status

Fixed

Version

10.3

Component
Media 

Last updated about 22 hours ago

Created by

🇷🇴Romania amateescu

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024