From b6fd29c9fd65288a0927a1faf598bd5cfdd75222 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 29 Nov 2024 00:22:20 +0100 Subject: [PATCH 1/2] refactor: remove bad caching --- app/helpers/avo/application_helper.rb | 2 +- lib/avo.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index af231f14b..d3bc0f216 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -65,7 +65,7 @@ def svg(file_name, **args) file_name = "#{file_name}.svg" unless file_name.end_with? ".svg" - Avo::CACHED_SVGS[file_name] ||= with_asset_finder(::Avo::SvgFinder) do + with_asset_finder(::Avo::SvgFinder) do inline_svg file_name, **args end end diff --git a/lib/avo.rb b/lib/avo.rb index 58aa29743..d2bb5de06 100644 --- a/lib/avo.rb +++ b/lib/avo.rb @@ -19,7 +19,6 @@ module Avo COOKIES_KEY = "avo" MODAL_FRAME_ID = :modal_frame ACTIONS_BACKGROUND_FRAME = :actions_background - CACHED_SVGS = {} class LicenseVerificationTemperedError < StandardError; end From 1c1e3fd300181d8f352472a7b30e3b06bf04433f Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 29 Nov 2024 00:28:05 +0100 Subject: [PATCH 2/2] fix caching --- lib/avo.rb | 1 + lib/avo/svg_finder.rb | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/avo.rb b/lib/avo.rb index d2bb5de06..58aa29743 100644 --- a/lib/avo.rb +++ b/lib/avo.rb @@ -19,6 +19,7 @@ module Avo COOKIES_KEY = "avo" MODAL_FRAME_ID = :modal_frame ACTIONS_BACKGROUND_FRAME = :actions_background + CACHED_SVGS = {} class LicenseVerificationTemperedError < StandardError; end diff --git a/lib/avo/svg_finder.rb b/lib/avo/svg_finder.rb index cc3fd4e3b..91b093137 100644 --- a/lib/avo/svg_finder.rb +++ b/lib/avo/svg_finder.rb @@ -9,13 +9,15 @@ def initialize(filename) # Use the default static finder logic. If that doesn't find anything, search according to our pattern: def pathname - found_asset = default_strategy + Avo::CACHED_SVGS[@filename] ||= begin + found_asset = default_strategy - # Use the found asset - return found_asset if found_asset.present? + # Use the found asset + return found_asset if found_asset.present? - paths.find do |path| - File.exist? path + paths.find do |path| + File.exist? path + end end end