Media PDF Thumbnail: generate thumbnails in a lazy way

Created on 20 February 2023, almost 2 years ago
Updated 15 August 2023, over 1 year ago

Problem/Motivation

As the contrib module creates the thumbnails with FieldFormatter it does this during the same request as the complete page is rendered. In case of media overview or any other page that has multiple media items with PDF Thumbnail, this can take a lot of time.

Steps to reproduce

  1. Create 20-25 media items of type File.
  2. Install Media PDF Thumbnail module.
  3. Configure media overview view to display PDF thumbnails for media items of type File.
  4. Visit media overview page and filter by type "File".
  5. Observe very long loading time. Sometimes page would not load at all depending on ImageMagick settings.

Proposed resolution

Delegate thumbnail creation to a cron job. During the request check whether thumbnail exists and if not add the item to the queue. After the queue is processed, invalidate the media item cache tag, so that the new thumbnail is visible. Media in core has "Generate thumbnail on cron" setting per bundle. It would be nice that this setting is respected. So this can be on demand only. Make cron setting disabled by default, so that the current behavior is untouched.

Remaining tasks

Create a patch for "Media PDF Thumbnail" module.

User interface changes

None

API changes

None

Data model changes

None

Feature request
Status

Fixed

Version

5.4

Component

Code

Created by

🇩🇪Germany a.dmitriiev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @a.dmitriiev
  • @admitriiev opened merge request.
  • Status changed to Needs review almost 2 years ago
  • Assigned to hanan alasari
  • Status changed to RTBC almost 2 years ago
  • 🇩🇪Germany hanan alasari kassel
    • - I have first create fresh D10 and cloned the repo from https://www.drupal.org/project/media_pdf_thumbnail/git-instructions
    • - Installed the module with composer
    • - Enable media module and add more than 20 files.
    • - Enable media_pdf_thumbnail module
    • - Change the media view display to use PDF thumbnails for media.
    • - Run the cron /admin/config/system/cron or just run drush cron.
    • - Go to the media view and configure field: Media: Thumbnail to use Media PDF Thumbnail Image Formatter settings and enable the checkbox
    • to which page is use the thumbnail and this should be in this case just for file media type.
    • - Test.. loading time looks good and i can see the thumbnails made from the first page of the PDF file.
  • 🇩🇪Germany a.dmitriiev

    Attaching the patch here too.

  • 🇫🇷France sgostanyan

    Thanks for proposing that feature.

    The generation in cron/queue has been added in version 6.x but in a different way. The formatter itself get that option, the Media "Queue thumbnail downloads" is not used for two reasons.
    The first one is because we decided to let users to use the queueing system separately for each formatter in each view mode, for a finnest configuration.
    The second one is because some people use that module for other entities than Media. It works for any fields (usage of any image field with any file field) in any entity, so we want that users have also the opportunity to take advantage of that feature.

    As version 6.x is still in beta, that patch will be usefull for those who want cron/queue feature for now. But it will not be included in 5.x release for avoiding confusion when upgrading to version 6.

    King regards

  • Status changed to Fixed over 1 year ago
Production build 0.71.5 2024