Unified · Split
| @@ -11,20 +11,22 @@ module Docs · 10 unmodified lines | |||
| 11 | @image_optim.optimize_image_data(data) | 11 | @image_optim.optimize_image_data(data) |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | def self.cache | ||
| 15 | @cache ||= {} | ||
| 16 | end | ||
| 17 | |||
| 14 | def call | 18 | def call |
| 15 | return doc if context[:download_images] == false | 19 | return doc if context[:download_images] == false |
| 16 | 20 | ||
| 17 | @@cache ||= {} | ||
| 18 | |||
| 19 | doc.css('img[src]').each do |node| | 21 | doc.css('img[src]').each do |node| |
| 20 | src = node['src'] | 22 | src = node['src'] |
| 21 | 23 | ||
| 22 | if @@cache.key?(src) | 24 | if self.class.cache.key?(src) |
| 23 | node['src'] = @@cache[src] unless @@cache[src] == false | 25 | node['src'] = self.class.cache[src] unless self.class.cache[src] == false |
| 24 | next | 26 | next |
| 25 | end | 27 | end |
| 26 | 28 | ||
| 27 | @@cache[src] = false | 29 | self.class.cache[src] = false |
| 28 | 30 | ||
| 29 | url = Docs::URL.parse(src) | 31 | url = Docs::URL.parse(src) |
| 30 | url.scheme = 'https' if url.scheme.nil? | 32 | url.scheme = 'https' if url.scheme.nil? |
| @@ -57,7 +59,7 @@ module Docs · 26 unmodified lines | |||
| 57 | 59 | ||
| 58 | image = Base64.strict_encode64(image) | 60 | image = Base64.strict_encode64(image) |
| 59 | image.prepend "data:#{response.mime_type};base64," | 61 | image.prepend "data:#{response.mime_type};base64," |
| 60 | node['src'] = @@cache[src] = image | 62 | node['src'] = self.class.cache[src] = image |
| 61 | end | 63 | end |
| 62 | rescue => exception | 64 | rescue => exception |
| 63 | instrument 'error.image', url: url, exception: exception | 65 | instrument 'error.image', url: url, exception: exception |