From 3b4151b7735b29795d77b9e4bb01a9257813204c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 15 Mar 2019 22:22:30 +0530 Subject: [PATCH] Cache computed item property (#7301) Merge pull request 7301 --- lib/jekyll/filters.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 23ad0cde..01fd0372 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -324,14 +324,18 @@ module Jekyll end def item_property(item, property) - if item.respond_to?(:to_liquid) - property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute| - parse_sort_input(subvalue[attribute]) + @item_property_cache ||= {} + @item_property_cache[property] ||= {} + @item_property_cache[property][item] ||= begin + if item.respond_to?(:to_liquid) + property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute| + parse_sort_input(subvalue[attribute]) + end + elsif item.respond_to?(:data) + parse_sort_input(item.data[property.to_s]) + else + parse_sort_input(item[property.to_s]) end - elsif item.respond_to?(:data) - parse_sort_input(item.data[property.to_s]) - else - parse_sort_input(item[property.to_s]) end end