Cleaned up caching in AbstractReferenceFilter
Cleaning this up any further is a bit tricky as the caches in question should only be evaluated if RequestStore is actually enabled.
This commit is contained in:
parent
ede351a99e
commit
915fd3f910
1 changed files with 11 additions and 15 deletions
|
@ -74,11 +74,7 @@ module Banzai
|
||||||
if RequestStore.active?
|
if RequestStore.active?
|
||||||
cache = find_objects_cache[object_class][project.id]
|
cache = find_objects_cache[object_class][project.id]
|
||||||
|
|
||||||
if cache.key?(id)
|
get_or_set_cache(cache, id) { find_object(project, id) }
|
||||||
cache[id]
|
|
||||||
else
|
|
||||||
cache[id] = find_object(project, id)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
find_object(project, id)
|
find_object(project, id)
|
||||||
end
|
end
|
||||||
|
@ -88,11 +84,7 @@ module Banzai
|
||||||
if RequestStore.active?
|
if RequestStore.active?
|
||||||
cache = project_refs_cache
|
cache = project_refs_cache
|
||||||
|
|
||||||
if cache.key?(ref)
|
get_or_set_cache(cache, ref) { project_from_ref(ref) }
|
||||||
cache[ref]
|
|
||||||
else
|
|
||||||
cache[ref] = project_from_ref(ref)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
project_from_ref(ref)
|
project_from_ref(ref)
|
||||||
end
|
end
|
||||||
|
@ -107,11 +99,7 @@ module Banzai
|
||||||
if RequestStore.active?
|
if RequestStore.active?
|
||||||
cache = url_for_object_cache[object_class][project.id]
|
cache = url_for_object_cache[object_class][project.id]
|
||||||
|
|
||||||
if cache.key?(object)
|
get_or_set_cache(cache, object) { url_for_object(object, project) }
|
||||||
cache[object]
|
|
||||||
else
|
|
||||||
cache[object] = url_for_object(object, project)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
url_for_object(object, project)
|
url_for_object(object, project)
|
||||||
end
|
end
|
||||||
|
@ -243,6 +231,14 @@ module Banzai
|
||||||
hash[key] = Hash.new { |h, k| h[k] = {} }
|
hash[key] = Hash.new { |h, k| h[k] = {} }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_or_set_cache(cache, key)
|
||||||
|
if cache.key?(key)
|
||||||
|
cache[key]
|
||||||
|
else
|
||||||
|
cache[key] = yield
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue