don't even MultiCache FeatureFlags.feature_flag_account_ids for root accounts

it'll never hit the db anyway, because it knows it has no parents, so it's a
useless caching

Change-Id: Ie6496b1dbcec1ddc3a32da52cdff7c1614b0d14b
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/271527
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2021-08-16 14:13:15 -06:00
parent 4be277d9cc
commit 63bf92f4c1
1 changed files with 10 additions and 3 deletions

View File

@ -104,12 +104,19 @@ module FeatureFlags
# starting with site admin
def feature_flag_account_ids
return [Account.site_admin.global_id] if is_a?(User)
return [] if self.is_a?(Account) && self.site_admin?
return [] if is_a?(Account) && site_admin?
# don't use a cache at all for root account, because
# it won't even hit the database
if is_a?(Account) && root_account?
chain = account_chain(include_site_admin: true).dup
chain.shift
return chain.reverse.map(&:global_id)
end
cache = self.is_a?(Account) && root_account? ? MultiCache.cache : Rails.cache
RequestCache.cache('feature_flag_account_ids', self) do
shard.activate do
cache.fetch(['feature_flag_account_ids', self].cache_key) do
Rails.cache.fetch(['feature_flag_account_ids', self].cache_key) do
chain = account_chain(include_site_admin: true).dup
chain.shift if is_a?(Account)
chain.reverse.map(&:global_id)