Skip to content

Commit

Permalink
Cache the is_sharded? status of the model
Browse files Browse the repository at this point in the history
Sets self.sharded depending on the superclass, if it is not otherwise
set.
  • Loading branch information
KJ Tsanaktsidis committed Apr 5, 2023
1 parent 8f39606 commit f66d884
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_record_shards/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit f66d884

Please sign in to comment.