Uploading a file to media library flushes theme registry

Created on 10 April 2024, 8 months ago
Updated 8 May 2024, 8 months ago

Problem

During a load-test on a client site we ran into a performance problem: When uploading a file into the media library, the consequent request became very slow under high load (up to ~25seconds).

Steps to reproduce

  • When uploading a file via the media library, the file is moved into temp store
  • The media library upload form uses the FileRepository::move() method to move the file to the final, permanent location
  • filerepository::move() invokes hook_file_move, resulting in image_move hook flushing the image style for the source image
  • Image style flushing clears the theme registry and invalidates cache-tags of the complete image style:
        // Clear caches so that formatters may be added for this style.
        \Drupal::service('theme.registry')->reset();
      Cache::invalidateTags($this
        ->getCacheTagsToInvalidate());
    

The problem does not appear when using a regular file upload, e.g. via file widget, without the media-library. This is because the regular file upload does not use FileRepository::move() but directly uses FileSystem::move()

Possilbe resolution

One of:

  • Improve ImageStyle::flush() to not clear the theme registry if a path is given

The problem seems to be caused by πŸ› hook_image_style_flush doesn't get the $path passed to Drupal\image\Entity\ImageStyle::flush() method Fixed

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
MediaΒ  β†’

Last updated 4 days ago

Created by

πŸ‡¦πŸ‡ΉAustria fago Vienna

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024