forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_account.rb
More file actions
38 lines (30 loc) · 998 Bytes
/
Copy pathload_account.rb
File metadata and controls
38 lines (30 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class LoadAccount
def initialize(app)
@app = app
end
def call(env)
clear_caches
domain_root_account = ::LoadAccount.default_domain_root_account
configure_for_root_account(domain_root_account)
env['canvas.domain_root_account'] = domain_root_account
@app.call(env)
end
def self.default_domain_root_account; Account.default; end
def clear_caches
::Account.clear_special_account_cache!(::LoadAccount.force_special_account_reload)
::LoadAccount.clear_shard_cache
end
def self.clear_shard_cache
@timed_cache ||= TimedCache.new(-> { Setting.get('shard_cache_time', 60).to_i.seconds.ago }) do
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
protected
def configure_for_root_account(domain_root_account)
Attachment.domain_namespace = domain_root_account.file_namespace
end
end