Verified Commit 22d14407 authored by Sean McGivern's avatar Sean McGivern

Reduce time spent in breadcrumbs

This takes the time spent in a local profile from 19% of the total build
time to 4%.
parent 89b942dd
Pipeline #40978384 (#78701) passed with stages
in 18 minutes and 30 seconds
......@@ -21,8 +21,7 @@ class Breadcrumbs < Middleman::Extension
end
def breadcrumbs(page, separator: @separator, wrapper: @wrapper, hide_home: @hide_home, convert_last: @convert_last)
hierarchy = [page]
hierarchy.unshift hierarchy.first.parent while hierarchy.first.parent
hierarchy = parents(page)
hierarchy.collect.with_index do |page_v, i|
if show_page(page_v, hide_home)
if convert_last_to_link(i, hierarchy.size, convert_last)
......@@ -36,6 +35,26 @@ class Breadcrumbs < Middleman::Extension
private
def parents(page)
current_page = page
hierarchy = []
while current_page
hierarchy.unshift(current_page)
current_page = parent(current_page)
end
hierarchy
end
def parent(page)
@parent_hash ||= Hash.new do |hash, key|
hash[key] = key.parent
end
@parent_hash[page]
end
def wrap(content, wrapper: nil)
wrapper ? content_tag(wrapper) { content } : content
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