Media library potentially triggers remote oEmbed request for each media item

Created on 10 June 2024, 4 months ago
Updated 17 July 2024, 3 months ago

Problem/Motivation

The following three circumstances don't play together well:

  1. OEmbed::getMetadata() fetches the oEmbed resource regardless of the metadata attribute being fetched. If the resource data is not cached (because, for example, the entire cache was just cleared) this means an actual HTTP request is performed against the resource URL
  2. Media adds a theme suggestion containing the oEmbed provider name to list of suggestions for rendered media. This allows, for example, styling YouTube and Vimeo thumbnails differently, even though they belong to the same bundle (Remote video). To do this Media needs to call OEmbed::getMetadata()
  3. The media library may contain up to 24 rendered media items

Steps to reproduce

Put together, if the most recent 24 media items on your site are YouTube videos and you visit the media library immediately after a cache clear, Drupal will perform 24 oEmbed requests to YouTube in order to determine that each of these videos is, in fact, from YouTube. That's not ideal.

Proposed resolution

There are different possible solutions to this:

  1. Do nothing, and accept that this can happen
  2. Remove the theme suggestion based on the provider name
  3. Change the theme suggestion logic to only add the provider name if the provider name field is mapped to a field and then use the field value to create the suggestion
  4. Make OEmbed::getMetadata() not fetch the oEmbed resource when just returning provider info (in particular, for the provider_name and provider_url attributes). Instead call UrlResolver::getProviderByUrl() for those two attribute names. Note that there is a potential performance regression interms of HTTP requests here, in case the resource URL and the resource data are both in the cache but the provider list is not.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

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

Comments & Activities

  • Issue created by @tstoeckler
  • πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

    I pursued solution 4 initially for a bit locally, but having written the issue summary now, I think 3. is the way to go. Conceptually media metadata is allowed to be "expensive" and that's exactly why we have the concept of mapping it to local fields if it needs to be accessed regularly.

  • πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

    Since I have it laying around locally, maybe it helps someone: Here's a patch that adds an "oEmbed request log" by means of simply writing a log entry each time the oEmbed subsystem performs an HTTP request.

  • πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

    ...and here's a patch that implements 4. Not doing an MR as per #2 this would not be my preferred way of going forward but it is the least invasive workaround for people hitting this on their sites.

  • πŸ‡³πŸ‡ΏNew Zealand quietone
Production build 0.71.5 2024