From 456b8448e821880cd6bbc8a819210f8a3c387b11 Mon Sep 17 00:00:00 2001 From: Bojan Marjanovic Date: Wed, 21 May 2025 08:23:43 +0200 Subject: [PATCH] Prevent attr_encrypted from making queries on load `#attribute_instance_methods_as_symbols` can trigger a query when the schema cache is not loaded. We only need the results of this method if `attribute_instance_methods_as_symbols_available?` is true so we move this inside the check. Signed-off-by: Bojan Marjanovic --- lib/attr_encrypted.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/attr_encrypted.rb b/lib/attr_encrypted.rb index 5cb46c3f..7db13697 100644 --- a/lib/attr_encrypted.rb +++ b/lib/attr_encrypted.rb @@ -144,9 +144,8 @@ def attr_encrypted(*attributes) attributes.each do |attribute| encrypted_attribute_name = (options[:attribute] ? options[:attribute] : [options[:prefix], attribute, options[:suffix]].join).to_sym - instance_methods_as_symbols = attribute_instance_methods_as_symbols - if attribute_instance_methods_as_symbols_available? + instance_methods_as_symbols = attribute_instance_methods_as_symbols attr_reader encrypted_attribute_name unless instance_methods_as_symbols.include?(encrypted_attribute_name) attr_writer encrypted_attribute_name unless instance_methods_as_symbols.include?(:"#{encrypted_attribute_name}=")