diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 067648b7..209a3e0e 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -167,11 +167,23 @@ module Jekyll # # Returns the filtered array of objects def where(input, property, value) + return input if property.nil? || value.nil? return input unless input.respond_to?(:select) - input = input.values if input.is_a?(Hash) - input.select do |object| - Array(item_property(object, property)).map!(&:to_s).include?(value.to_s) - end || [] + input = input.values if input.is_a?(Hash) + input_id = input.hash + + # implement a hash based on method parameters to cache the end-result + # for given parameters. + @where_filter_cache ||= {} + @where_filter_cache[input_id] ||= {} + @where_filter_cache[input_id][property] ||= {} + + # stash or retrive results to return + @where_filter_cache[input_id][property][value] ||= begin + input.select do |object| + Array(item_property(object, property)).map!(&:to_s).include?(value.to_s) + end || [] + end end # Filters an array of objects against an expression