module Switchman::ActiveRecord::Base::ClassMethods
Public Instance Methods
clear_query_caches_for_current_thread()
click to toggle source
# File lib/switchman/active_record/base.rb, line 65 def clear_query_caches_for_current_thread ::ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool| pool.connection(switch_shard: false).clear_query_cache if pool.active_connection? end end
current_shard()
click to toggle source
significant change: _don't_ check if klasses.include?(Base
) i.e. other sharded models don't inherit the current shard of Base
# File lib/switchman/active_record/base.rb, line 73 def current_shard connected_to_stack.reverse_each do |hash| return hash[:shard] if hash[:shard] && hash[:klasses].include?(connection_classes) end default_shard end
find_ids_in_ranges(opts = {}, &block)
click to toggle source
# File lib/switchman/active_record/base.rb, line 9 def find_ids_in_ranges(opts = {}, &block) opts.reverse_merge!(loose: true) all.find_ids_in_ranges(opts, &block) end
integral_id?()
click to toggle source
# File lib/switchman/active_record/base.rb, line 22 def integral_id? @integral_id = columns_hash[primary_key]&.type == :integer if @integral_id.nil? @integral_id end
reset_column_information()
click to toggle source
Calls superclass method
# File lib/switchman/active_record/base.rb, line 47 def reset_column_information @sharded_column_values = {} super end
sharded_model()
click to toggle source
# File lib/switchman/active_record/base.rb, line 14 def sharded_model self.abstract_class = true return if self == UnshardedRecord Shard.send(:add_sharded_model, self) end
transaction(**)
click to toggle source
Calls superclass method
# File lib/switchman/active_record/base.rb, line 27 def transaction(**) if self != ::ActiveRecord::Base && current_scope current_scope.activate do db = Shard.current(connection_classes).database_server if ::GuardRail.environment == db.guard_rail_environment super else db.unguard { super } end end else db = Shard.current(connection_classes).database_server if ::GuardRail.environment == db.guard_rail_environment super else db.unguard { super } end end end
unscoped() { || ... }
click to toggle source
Calls superclass method
# File lib/switchman/active_record/base.rb, line 52 def unscoped if block_given? super do current_scope.shard_value = nil yield end else result = super result.shard_value = nil result end end