Commit 33ccfc23 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Move caching into model

parent b53f9d90
......@@ -675,10 +675,11 @@ class Project < ApplicationRecord
# '>' or its escaped form ('&gt;') are checked for because '>' is sometimes escaped
# when the reference comes from an external source.
def markdown_reference_pattern
%r{
#{reference_pattern}
(#{reference_postfix}|#{reference_postfix_escaped})
}x
@markdown_reference_pattern ||=
%r{
#{reference_pattern}
(#{reference_postfix}|#{reference_postfix_escaped})
}x
end
def trending
......
......@@ -24,6 +24,7 @@ module Banzai
end
def call
ref_pattern = Project.markdown_reference_pattern
ref_pattern_start = /\A#{ref_pattern}\z/
nodes.each do |node|
......@@ -82,7 +83,7 @@ module Banzai
refs = Set.new
nodes.each do |node|
node.to_html.scan(ref_pattern) do
node.to_html.scan(Project.markdown_reference_pattern) do
refs << "#{$~[:namespace]}/#{$~[:project]}"
end
end
......@@ -111,10 +112,6 @@ module Banzai
def link_tag(url, data, link_content, title)
%(<a href="#{url}" #{data} class="#{link_class}" title="#{escape_once(title)}">#{link_content}</a>)
end
def ref_pattern
@ref_pattern ||= Project.markdown_reference_pattern
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