implement a cache within the where filter (#6868)
Merge pull request 6868
This commit is contained in:
parent
beada92da8
commit
053b522a82
|
@ -167,11 +167,23 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the filtered array of objects
|
# Returns the filtered array of objects
|
||||||
def where(input, property, value)
|
def where(input, property, value)
|
||||||
|
return input if property.nil? || value.nil?
|
||||||
return input unless input.respond_to?(:select)
|
return input unless input.respond_to?(:select)
|
||||||
input = input.values if input.is_a?(Hash)
|
input = input.values if input.is_a?(Hash)
|
||||||
input.select do |object|
|
input_id = input.hash
|
||||||
Array(item_property(object, property)).map!(&:to_s).include?(value.to_s)
|
|
||||||
end || []
|
# 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
|
end
|
||||||
|
|
||||||
# Filters an array of objects against an expression
|
# Filters an array of objects against an expression
|
||||||
|
|
Loading…
Reference in New Issue