Commit 7f0fd73e authored by Yorick Peterse's avatar Yorick Peterse

Cache default_issues_tracker? in Banzai

Every object processed by ExternalIssueReferenceFilter can return a
different Project instance when calling "project". For example, every
note processed will have it's own associated Project. If we were to
cache Project#default_issues_tracker? on Project level this would have
no impact on Markdown rendering timings as the cache would have to be
built for every Project instance without it ever being re-used.

To work around this we cache Project#default_issues_tracker? in
Banzai::Filter::ExternalIssueReferenceFilter using the project's _id_
instead of the whole object. This setup allows re-using of the cached
data even when the Project instances used are different, as long as the
actual project IDs are the same.
parent 9fa94326
...@@ -35,7 +35,7 @@ module Banzai ...@@ -35,7 +35,7 @@ module Banzai
def call def call
# Early return if the project isn't using an external tracker # Early return if the project isn't using an external tracker
return doc if project.nil? || project.default_issues_tracker? return doc if project.nil? || default_issues_tracker?
ref_pattern = ExternalIssue.reference_pattern ref_pattern = ExternalIssue.reference_pattern
ref_start_pattern = /\A#{ref_pattern}\z/ ref_start_pattern = /\A#{ref_pattern}\z/
...@@ -90,6 +90,21 @@ module Banzai ...@@ -90,6 +90,21 @@ module Banzai
def url_for_issue(*args) def url_for_issue(*args)
IssuesHelper.url_for_issue(*args) IssuesHelper.url_for_issue(*args)
end end
def default_issues_tracker?
if RequestStore.active?
default_issues_tracker_cache[project.id] ||=
project.default_issues_tracker?
else
project.default_issues_tracker?
end
end
private
def default_issues_tracker_cache
RequestStore[:banzai_default_issues_tracker_cache] ||= {}
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