FEATURE: reset active record cache in sidekiq if needed

This can happen in multisite environments after restores
This commit is contained in:
Sam
2017-02-17 12:09:53 -05:00
parent 7a85469c4c
commit 1935f624b8
3 changed files with 22 additions and 22 deletions

View File

@ -111,29 +111,8 @@ class ApplicationController < ActionController::Base
end
end
def self.last_ar_cache_reset
@last_ar_cache_reset
end
def self.last_ar_cache_reset=(val)
@last_ar_cache_reset
end
rescue_from ActiveRecord::StatementInvalid do |e|
last_cache_reset = ApplicationController.last_ar_cache_reset
if e.message =~ /UndefinedColumn/ && (last_cache_reset.nil? || last_cache_reset < 30.seconds.ago)
Rails.logger.warn "Clear Active Record cache cause schema appears to have changed!"
ApplicationController.last_ar_cache_reset = Time.zone.now
ActiveRecord::Base.connection.query_cache.clear
(ActiveRecord::Base.connection.tables - %w[schema_migrations]).each do |table|
table.classify.constantize.reset_column_information rescue nil
end
end
Discourse.reset_active_record_cache_if_needed(e)
raise e
end