mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FEATURE: reset active record cache in sidekiq if needed
This can happen in multisite environments after restores
This commit is contained in:
parent
7a85469c4c
commit
1935f624b8
|
@ -111,29 +111,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
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|
|
rescue_from ActiveRecord::StatementInvalid do |e|
|
||||||
|
Discourse.reset_active_record_cache_if_needed(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
|
|
||||||
|
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class SidekiqLogsterReporter < Sidekiq::ExceptionHandler::Logger
|
||||||
def call(ex, context = {})
|
def call(ex, context = {})
|
||||||
|
|
||||||
return if Jobs::HandledExceptionWrapper === ex
|
return if Jobs::HandledExceptionWrapper === ex
|
||||||
|
Discourse.reset_active_record_cache_if_needed(ex)
|
||||||
|
|
||||||
# Pass context to Logster
|
# Pass context to Logster
|
||||||
fake_env = {}
|
fake_env = {}
|
||||||
|
|
|
@ -392,4 +392,24 @@ module Discourse
|
||||||
[SiteSetting.tos_topic_id, SiteSetting.guidelines_topic_id, SiteSetting.privacy_topic_id]
|
[SiteSetting.tos_topic_id, SiteSetting.guidelines_topic_id, SiteSetting.privacy_topic_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cattr_accessor :last_ar_cache_reset
|
||||||
|
|
||||||
|
def self.reset_active_record_cache_if_needed(e)
|
||||||
|
last_cache_reset = Discourse.last_ar_cache_reset
|
||||||
|
if e && 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!"
|
||||||
|
Discourse.last_ar_cache_reset = Time.zone.now
|
||||||
|
Discourse.reset_active_record_cache
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.reset_active_record_cache
|
||||||
|
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
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user