payload['url'] ?? '' ); $mobile = true === ( $job->payload['mobile'] ?? false ); if ( ! $this->targets->isOwnUrl( $url ) ) { throw new PermanentFailure( 'Refusing to preload a URL outside this site.' ); } if ( $this->isCached( $url, $mobile ) ) { return; } $this->pacer->beforeFetch(); $status = $this->client->fetch( $url, $mobile ); $this->pacer->afterFetch(); if ( $status >= 400 && $status < 500 && 429 !== $status ) { PermanentFailure::raise( 'Preload got HTTP %d.', (int) $status ); } if ( $status < 200 || $status >= 400 ) { throw new \RuntimeException( 'Preload got HTTP ' . (int) $status . '.' ); } } /** * Whether the page is already in the cache for this device. * * @param string $url URL. * @param bool $mobile Mobile variant. */ private function isCached( string $url, bool $mobile ): bool { $parts = Url::parse( $url ); if ( ! is_array( $parts ) || ! isset( $parts['host'] ) ) { return false; } // Same host[:port] as the request that stored the page (see PurgeService::purgeUrls). $host = $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ); $key = CacheKey::forUrl( $host, (string) ( $parts['path'] ?? '/' ), $mobile ); return null !== $key && null !== $this->store->fetch( $key, '' ); } }