Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/hijacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down