From f66d884de72dad8b8d0f5dcb6a92e044af7430f6 Mon Sep 17 00:00:00 2001 From: KJ Tsanaktsidis Date: Wed, 5 Apr 2023 15:14:02 +1000 Subject: [PATCH] Cache the is_sharded? status of the model Sets self.sharded depending on the superclass, if it is not otherwise set. --- lib/active_record_shards/model.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_record_shards/model.rb b/lib/active_record_shards/model.rb index 7d3c6581..d5e158c3 100644 --- a/lib/active_record_shards/model.rb +++ b/lib/active_record_shards/model.rb @@ -11,7 +11,8 @@ def not_sharded end def is_sharded? # rubocop:disable Naming/PredicateName - if self == ActiveRecord::Base + return self.sharded unless self.sharded.nil? + self.sharded = if self == ActiveRecord::Base sharded != false && supports_sharding? elsif self == base_class if sharded.nil?