git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 3bc2454e authored by mmn's avatar mmn

Avoid excessive remote requests on oEmbed lookups

I noticed that each time a notice was accessed it'd do a remote lookup
with HEAD (and continue despite 404 etc.) and then another attempt to
download the resource. If this wasn't successful new attempts would be
made for each loading of the resource, which is extremely resource
intensive.

Whenever we can say "it's been n seconds since the last attempt" we
could probably enable this again - or just manually reload remote
thumbnails (as part of the StoreRemoteMedia plugin etc.)
parent a7df79ac
......@@ -389,6 +389,13 @@ class OembedPlugin extends Plugin
// First see if it's too large for us
common_debug(__METHOD__ . ': '.sprintf('Performing HEAD request for remote file id==%u to avoid unnecessarily downloading too large files. URL: %s', $thumbnail->getFileId(), $remoteUrl));
$head = $http->head($remoteUrl);
if (!$head->isOk()) {
common_log(LOG_WARN, 'HEAD request returned HTTP failure, so we will abort now and delete the thumbnail object.');
$thumbnail->delete();
return false;
} else {
common_debug('HEAD request returned HTTP success, so we will continue.');
}
$remoteUrl = $head->getEffectiveUrl(); // to avoid going through redirects again
$headers = $head->getHeader();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment