Problem/Motivation
The following three circumstances don't play together well:
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- 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() - 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:
- Do nothing, and accept that this can happen
- Remove the theme suggestion based on the provider name
- 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
- Make
OEmbed::getMetadata()not fetch the oEmbed resource when just returning provider info (in particular, for theprovider_nameandprovider_urlattributes). Instead callUrlResolver::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.