Commit 915fd3f9 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent ede351a9
...@@ -74,11 +74,7 @@ module Banzai ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment