2017-04-28 03:51:01 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
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
|