2011-03-10 05:07:30 +08:00
|
|
|
class LoadAccount
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2014-08-26 22:53:26 +08:00
|
|
|
clear_caches
|
2013-03-21 04:30:20 +08:00
|
|
|
domain_root_account = ::LoadAccount.default_domain_root_account
|
2011-03-10 05:07:30 +08:00
|
|
|
configure_for_root_account(domain_root_account)
|
|
|
|
|
|
|
|
env['canvas.domain_root_account'] = domain_root_account
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
|
2011-12-13 01:17:35 +08:00
|
|
|
def self.default_domain_root_account; Account.default; end
|
|
|
|
|
2014-08-26 22:53:26 +08:00
|
|
|
def clear_caches
|
2015-09-22 05:26:53 +08:00
|
|
|
::Account.clear_special_account_cache!(::LoadAccount.force_special_account_reload)
|
2014-09-29 17:04:16 +08:00
|
|
|
::LoadAccount.clear_shard_cache
|
2014-08-26 22:53:26 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.clear_shard_cache
|
2015-12-22 23:32:29 +08:00
|
|
|
@timed_cache ||= TimedCache.new(-> { Setting.get('shard_cache_time', 60).to_i.seconds.ago }) do
|
2014-08-26 22:53:26 +08:00
|
|
|
Shard.clear_cache
|
|
|
|
end
|
|
|
|
@timed_cache.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
# this should really only be set to true in spec runs
|
|
|
|
cattr_accessor :force_special_account_reload
|
|
|
|
self.force_special_account_reload = false
|
|
|
|
|
2011-03-10 05:07:30 +08:00
|
|
|
protected
|
|
|
|
|
|
|
|
def configure_for_root_account(domain_root_account)
|
|
|
|
Attachment.domain_namespace = domain_root_account.file_namespace
|
|
|
|
end
|
|
|
|
end
|