diff --git a/lib/hijacker.rb b/lib/hijacker.rb index 16161da..4e92857 100644 --- a/lib/hijacker.rb +++ b/lib/hijacker.rb @@ -81,7 +81,7 @@ def self.connect(target_name, sister_name = nil, options = {}) #reenable_query_caching - reset_column_info_for_active_record + reset_column_info_for_active_record(target_name) run_after_hijack_callback @@ -299,8 +299,14 @@ def self.run_after_hijack_callback # Reset column information to ensure models are up-to-date with the new schema. # This ensures that any changes to the database schema are immediately # in a multi-tenant architecture where different tenants might have - def self.reset_column_info_for_active_record - ::ActiveRecord::Base.descendants.each do |klass| + def self.reset_column_info_for_active_record(target_name) + descendants_key = "#{target_name}/hijacker_descendants" + descendants = $redis.get(descendants_key) + if descendants.blank? + descendants = ::ActiveRecord::Base.descendants + $redis.setex(descendants_key, 12.hours,descendants) + end + descendants.each do |klass| klass.reset_column_information end end