I’m working on a PR for this issue: Extra calls to Active Record encryption key provider · Issue #42388 · rails/rails · GitHub
The problem with the current implementation is that when using an external key management service, we currently end up with 3 calls to
#encryption_key instead of, ideally, one.
With the following patch I have 2 calls instead of 3 which is an okay-enough optimization IMO but as I’m rather new to rails contribution, I prefer making sure I’m not breaking something or creating an undesirable side-effect.
diff --git a/activerecord/lib/active_record/encryption/encrypted_attribute_type.rb b/activerecord/lib/active_record/encryption/encrypted_attribute_type.rb
index 7cdb4b18bb..1ffc5ab7bc 100644
@@ -26,6 +26,10 @@ def initialize(scheme:, cast_type: ActiveModel::Type::String.new, previous_type:
@previous_type = previous_type
+ def cast(value)