AMP_Image_Dimension_Extractor::determine_which_images_to_fetch PHP Метод

determine_which_images_to_fetch() приватный статический Метод

Creates a short lived transient that acts as a semaphore so that another visitor doesn't trigger a remote fetch for the same image at the same time.
private static determine_which_images_to_fetch ( array &$dimensions, array &$urls_to_fetch )
$dimensions array Image urls mapped to dimensions.
$urls_to_fetch array Urls of images to fetch because dimensions are not in transient/cache.
    private static function determine_which_images_to_fetch(&$dimensions, &$urls_to_fetch)
    {
        foreach ($dimensions as $url => $value) {
            // Check whether some other callback attached to the filter already provided dimensions for this image.
            if (is_array($value)) {
                continue;
            }
            $url_hash = md5($url);
            $transient_name = sprintf('amp_img_%s', $url_hash);
            $cached_dimensions = get_transient($transient_name);
            // If we're able to retrieve the dimensions from a transient, set them and move on.
            if (is_array($cached_dimensions)) {
                $dimensions[$url] = array('width' => $cached_dimensions[0], 'height' => $cached_dimensions[1]);
                continue;
            }
            // If the value in the transient reflects we couldn't get dimensions for this image the last time we tried, move on.
            if (self::STATUS_FAILED_LAST_ATTEMPT === $cached_dimensions) {
                $dimensions[$url] = false;
                continue;
            }
            $transient_lock_name = sprintf('amp_lock_%s', $url_hash);
            // If somebody is already trying to extract dimensions for this transient right now, move on.
            if (false !== get_transient($transient_lock_name)) {
                $dimensions[$url] = false;
                continue;
            }
            // Include the image as a url to fetch.
            $urls_to_fetch[$url]['url'] = $url;
            $urls_to_fetch[$url]['transient_name'] = $transient_name;
            $urls_to_fetch[$url]['transient_lock_name'] = $transient_lock_name;
            set_transient($transient_lock_name, 1, MINUTE_IN_SECONDS);
        }
    }