Project

General

Profile

Patch #41919 » 0002-Calling-MiniMagick-every-time-is-slow-so-I-m-going-t.patch

Kota Shiratsuka, 2024-12-02 12:33

View differences:

app/helpers/application_helper.rb
1007 1007
          title_and_alt = other_attrs.scan(title_and_alt_re).to_h
1008 1008
          other_attrs.gsub!(title_and_alt_re, '')
1009 1009

  
1010
          # Process dimensions and scaling
1011
          width, height = nil, nil
1012
          image = MiniMagick::Image.open(found.diskfile)
1013
          width, height = image.width, image.height
1014

  
1015
          # Adjust dimensions for @2x, @3x, etc.
1016
          if filename =~ /@(\d+)x\./
1017
            scale_factor = $1.to_i
1018
            width /= scale_factor
1019
            height /= scale_factor
1010
          # Get cache store configuration
1011
          config = Rails.application.config.redmine_image_cache_store rescue :memory_store
1012
          cache_store = ActiveSupport::Cache.lookup_store(config)
1013

  
1014
          # Use digest from the database as cache key
1015
          cache_key = "image_dimensions:#{found.digest}"
1016

  
1017
          # Cache dimensions and retrieve from Redis or memory store
1018
          dimensions = cache_store.fetch(cache_key) do
1019
            # Process dimensions and scaling
1020
            image = MiniMagick::Image.open(found.diskfile)
1021
            width, height = image.width, image.height
1022

  
1023
            # Adjust dimensions for @2x, @3x, etc.
1024
            if filename =~ /@(\d+)x\./
1025
              scale_factor = $1.to_i
1026
              width /= scale_factor
1027
              height /= scale_factor
1028
            end
1029

  
1030
            { width: width, height: height }
1020 1031
          end
1021 1032

  
1033
          width = dimensions[:width]
1034
          height = dimensions[:height]
1035

  
1022 1036
          # Add width and height to the img tag only if style attribute is absent
1023 1037
          dimension_attrs = (!has_style && width && height) ? " width=\"#{width}\" height=\"#{height}\"" : ""
1024 1038

  
config/environments/production.rb
45 45
  # Using Redis Store
46 46
  config.cache_store = :redis_cache_store, { path: '/var/run/valkey/valkey.sock' }
47 47
  config.redmine_search_cache_store = :redis_cache_store, { path: '/var/run/valkey/valkey.sock' }
48
  config.redmine_image_cache_store = :redis_cache_store, { path: '/var/run/valkey/valkey.sock' }
48 49

  
49 50
  # Send deprecation notices to registered listeners.
50 51
  config.active_support.deprecation = :log
(3-3/5)