Unverified Commit 59721e98 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3416508 by Niklan, Anybody, odi, catch, Grevil, herve001: Skip...

Issue #3416508 by Niklan, Anybody, odi, catch, Grevil, herve001: Skip generating aggregates that won't be used for stale asset requests

(cherry picked from commit cdfabaf1)
parent 874a2b09
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -28,10 +28,12 @@ public function __construct(protected readonly LoggerInterface $logger) {}
   */
  public function optimize(array $js_asset) {
    if ($js_asset['type'] !== 'file') {
      throw new \Exception('Only file JavaScript assets can be optimized.');
      throw new \Exception("Error trying to optimize JavaScript asset: {$js_asset['data']}. Only file JavaScript assets can be optimized.");
    }
    // Note, that files with "preprocess" set to FALSE should never even enter
    // this method.
    if (!$js_asset['preprocess']) {
      throw new \Exception('Only file JavaScript assets with preprocessing enabled can be optimized.');
      throw new \Exception("Error trying to optimize JavaScript asset: {$js_asset['data']}. Only file JavaScript assets with preprocessing enabled can be optimized.");
    }

    // If a BOM is found, convert the file to UTF-8, then use substr() to
+5 −6
Original line number Diff line number Diff line
@@ -182,12 +182,6 @@ public function deliver(Request $request, string $file_name) {
    // Generate a hash based on the asset group, this uses the same method as
    // the collection optimizer does to create the filename, so it should match.
    $generated_hash = $this->generateHash($group);
    $data = $this->optimizer->optimizeGroup($group);

    $response = new Response($data, 200, [
      'Cache-control' => static::CACHE_CONTROL,
      'Content-Type' => $this->contentType,
    ]);

    // However, the hash from the library definitions in code may not match the
    // hash from the URL. This can be for three reasons:
@@ -202,7 +196,12 @@ public function deliver(Request $request, string $file_name) {
    // from filling the disk, while still serving aggregates that may be
    // referenced in cached HTML.
    if (hash_equals($generated_hash, $received_hash)) {
      $data = $this->optimizer->optimizeGroup($group);
      $this->dumper->dumpToUri($data, $this->assetType, $uri);
      $response = new Response($data, 200, [
        'Cache-control' => static::CACHE_CONTROL,
        'Content-Type' => $this->contentType,
      ]);
    }
    else {
      $expected_filename = $this->fileExtension . '_' . $generated_hash . '.' . $this->fileExtension;