Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the youtube_tokens()
function, there's a test to see if the YouTube thumbnail already exists:
$file_uri = youtube_build_thumbnail_uri($video_id);
$file_url = file_create_url($file_uri);
if (file_exists($file_url) || youtube_get_remote_image($video_id)) {
It believe that it should be $file_uri
that's passed to file_exists()
, not $file_url
.
Because the file_exists()
is always failing, the thumbnail image is being recreated on every call.
In the general run of affairs this is fine, and wouldn't be noticed; in our case, however, with a high-traffic site where the tokenized image was being called several times a second, it dramatically increased the load on our server.
I've attached a patch.
Comment | File | Size | Author |
---|---|---|---|
#2 | avoid_recreating_video_thumbnail_on_each_call-2902588-1.patch | 686 bytes | reinvented |
Comments
Comment #2
reinvented CreditAttribution: reinvented as a volunteer commentedComment #3
guschilds CreditAttribution: guschilds commentedComment #4
GoldTested this with a number of nodes. The token call does indeed always fail on the $file_url.
The patch allows this to work as desired.
Comment #5
imyaro CreditAttribution: imyaro at DrupalJedi commentedComment #7
imyaro CreditAttribution: imyaro at DrupalJedi commentedThanks for the patch, works OK