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.
This commit is contained in:
Yorick Peterse 2016-03-30 14:04:28 +02:00
parent 9fa94326db
commit 7f0fd73eeb
1 changed files with 16 additions and 1 deletions

View File

@ -35,7 +35,7 @@ module Banzai
def call
# 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_start_pattern = /\A#{ref_pattern}\z/
@ -90,6 +90,21 @@ module Banzai
def url_for_issue(*args)
IssuesHelper.url_for_issue(*args)
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